I would like to have the upload component but change the text on the button (or maybe its entire content through a render fragment template) through a Parameter on the component level.
At the moment I can only do this through localization for all components.
---
ADMIN EDIT
---
The request targets both the Upload and the FileSelect components.
I would like to have my users click my own button or element to trigger the file select dialog that you get from clicking the "Select Files..." button on the Upload component.
A workaround is to use a function like this
window.customUploadClick = function () {
$('.k-upload-button input').trigger('click');
}
---
ADMIN EDIT
Completed with 3.0.0 release
If you are not using jQuery already, you don't have to add it for this, standard browser API can do this too:
@inject IJSRuntime _js
<script suppress-error="BL9992">
window.customUploadClick = function () {
document.querySelector(".k-upload-button input").click();
}
</script>
<TelerikButton OnClick="@InvokeSelectClick">invoke click</TelerikButton>
<TelerikUpload></TelerikUpload>
@code{
async Task InvokeSelectClick()
{
await _js.InvokeVoidAsync("customUploadClick");
}
}
---
Like in the Kendo Upload https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/configuration/files - I want to show some files initially to my user
=====
ADMIN EDIT:
A possible workaround is to use a ListView and mimic the Upload/FileSelect interface:
<TelerikUpload SaveUrl="api/upload/save"
RemoveUrl="api/upload/remove">
</TelerikUpload>
@{
if (OldFiles.Any())
{
<p>Older files:</p>
<div class="k-upload">
<ul class="k-upload-files k-reset">
<TelerikListView Data="@OldFiles" @ref="@ListView">
<Template>
<li class="k-file k-file-success">
<div class="k-file-single">
<span class="k-file-group-wrapper">
<span class="k-file-group k-icon k-i-file"></span>
</span>
<span class="k-file-name-size-wrapper">
<span class="k-file-name " title="@context.Name"> @context.Name </span>
<span class="k-file-validation-message k-text-success">Existing file.</span>
</span>
<span class="k-upload-status">
<TelerikButton ButtonType="@ButtonType.Button" Title="Remove"
OnClick="@( _ => RemoveOldFile(context) )"
Icon="x" FillMode="@ThemeConstants.Button.FillMode.Flat" />
</span>
</div>
</li>
</Template>
</TelerikListView>
</ul>
</div>
}
}
@code {
TelerikListView<UploadedFile> ListView { get; set; }
List<UploadedFile> OldFiles { get; set; } = new List<UploadedFile>()
{
new UploadedFile() { Id = 1, Name = "foo.txt" },
new UploadedFile() { Id = 2, Name = "bar.txt" },
};
async Task RemoveOldFile(UploadedFile file)
{
// delete the file from the remote server...
// ...
// update the client UI
OldFiles.Remove(file);
ListView.Rebind();
}
public class UploadedFile
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Please provide item templates for the file list, similar to:
<TelerikUpload SaveUrl="@SaveUrl"
RemoveUrl="@RemoveUrl"
AllowedExtensions="@( new List<string>() { ".pdf", ".docx" } )"
OnSelect="@OnSelectHandler"
OnCancel="@OnCancelHandler"
OnRemove="@OnRemoveHandler">
</TelerikUpload>
When the AllowedExtensions is set for the Telerik Upload control, it is expected that the File selection dialog box should filter the files by the file types in the Allowed extensions only. However, the dialog shows all files.
------
ADMIN EDIT
This will likely be exposed via the accept attribute the <input type=file> exposes. Note that it requires MIME types, not extensions.
At the moment, the extension can be filtered only after the file is selected: https://docs.telerik.com/blazor-ui/components/upload/validation.
-----
Is it possible to programmatically perform actions on the uploader, such as to remove files, rather than having to click on the remove button on each uploaded file?
---
ADMIN EDIT
Might be related to the ability to have initial files shown in the list: https://feedback.telerik.com/blazor/1485660-initial-files-in-blazor-upload.
At the moment, you could try using JS Interop to loop over the list, determine which file you want to remove and .click() its remove button. Here is a basic example of getting the buttons to click the second one. You could traverse the DOM to get the file name, or you could keep a collection of the files to use indexes in a fashion similar to this example.
@inject IJSRuntime _js
@* move this script to a correct location it's here as ahack to make the snippet shorter and easy to copy *@
<script suppress-error="BL9992">
function removeSecondFile(){
var deleteButtons = document.querySelectorAll("li.k-file button span.k-delete");
if(deleteButtons && deleteButtons.length > 1){
deleteButtons[1].click();
}
}
</script>
<TelerikUpload AutoUpload="false" SaveUrl="my-endpoint"></TelerikUpload>
<TelerikButton OnClick="@RemoveSecondFile">Remove second file</TelerikButton>
@code{
async Task RemoveSecondFile()
{
await _js.InvokeVoidAsync("removeSecondFile");
}
}
---
I am trying to upload files to an URL that is not in my control and it requires the PUT HTTP method. The Telerik Blazor Upload always uses a POST.
I imagine API like this would be nice:
<TelerikUpload SaveUrl="@SaveUrl" SaveMethod="PUT">
</TelerikUpload>
---
ADMIN EDIT
In the meantime, there are two possible solutions:
---
When the Upload has Initial Files, the RemoveUrl endpoint is not called when the user removes them from the UI.
===
TELERIK EDIT
The current workaround is to call the RemoveUrl in the Upload's OnRemove event handler. This is also applicable when you need to send additional custom data with the file name.
.razor file
@inject HttpClient HttpClient
<TelerikUpload OnRemove="@OnUploadRemove" RemoveUrl="@RemoveUrl" />
@code {
private string RemoveUrl { get; set; } = "api/upload/remove";
private async Task OnUploadRemove(UploadEventArgs args)
{
// code for non-initial files
// send optional custom data to the controller
args.RequestData.Add("requestKey", "custom value");
// code for initial files
// call the RemoveUrl
if (args.Files.First().Status == UploadFileStatus.Blank)
{
var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new StringContent(args.Files.First().Name), "files"); // "files" must match the RemoveField value
multipartContent.Add(new StringContent("requestKey"), "custom value"); // send optional custom data to the controller
await HttpClient.PostAsync(RemoveUrl, multipartContent);
}
}
}
Program.cs
builder.Services.AddHttpClient();
Accessibility issue
impacts screen reader user
[WCAG 1.3.1 level A] [WCAG 4.1.3 level AA]
tested using NVDA on chrome browser
on selecting upload button (w/ files already chosen) user is not advised the overall status of the files or individual files.
A visual user is informed;
This has not been 100% tested, as the upload was not targeted to an end point.
Suggestion: use aria-live
Also note, on selecting the upload button the focus is returned to input, and input says no files.
Impacts screen reader users
[WCAG 1.3.1 level A] [WCAG 4.1.3 level AA]
tested using NVDA on chrome browser
input (type="file") status always reads as 'no file chosen' when one or more files have been chosen (correct when no files are chosen).
on choosing a file to upload (so no file chosen yet), screen reader advises; web page title, chrome, page contents, file input status (same behaviour as default html 5 file input). On choosing a file a default browser html 5 file input will advise a file has been chosen. The list shown below the Telerik component is not known to a screen reader user