CustomFormData doesn't seem to work in OnUploadStart

I am trying to send *per file* form data with the upload when uploading multiple files.

<SfUploader AutoUpload="false" MaxFileSize="@maxFileSize">
    <UploaderEvents OnUploadStart="OnUploadStart"></UploaderEvents>
    <UploaderAsyncSettings SaveUrl="api/Upload/Save" ChunkSize=50000000></UploaderAsyncSettings>
</SfUploader>


private async void OnUploadStart(UploadingEventArgs args) {
args.CustomFormData = new[] { new { Name = "test-id", Value = Guid.NewGuid().ToString() } };
}


The form data is not being sent to the server.

If I do this in the FileSelected event (for example), then the form data fields are sent, however, they are the same for every file. I need the form data to be unique per multipart section.


The issue is that filenames may be identical (for example, if the user selects "test.jpg" from folder A and "test.jpg" from folder B, there is no way to tell them apart on the server as no path information is sent, which makes chunk processing impossible (the chunk processing example given relies on matching the filename).


The documentation says the OnUploadStart event is "used to add a parameter to the upload request"

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Inputs.UploaderEvents.html#Syncfusion_Blazor_Inputs_UploaderEvents_OnUploadStart

And the documentation for the UploadingEventArgs object says that the CustomFormData property "Gets or sets the additional data in key and value pair format to be submitted to the upload action."

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Inputs.UploadingEventArgs.html


2 Replies

AH Aleks Huson July 22, 2023 02:22 AM UTC

Any ideas?



KP Kokila Poovendran Syncfusion Team July 24, 2023 01:42 PM UTC

Hi Aleks Huson,

We apologize for any inconvenience you've faced. Regarding the use of "CustomFormData" in the "OnUploadStart" event, we regret to inform you that it is currently supported only in the "BeforeUpload" event and not in the "OnUploadStart" event.

If you need to generate a unique ID for each request in the FileSelected event, we recommend selecting the files one by one instead of selecting multiple files at a time. In our implementation, we consider multiple file requests as a single request, which is why the ID is not unique for all files. This behavior is intended. 


If you encounter scenarios where the same filename is used in the uploader, we suggest modifying or renaming the filename to ensure uniqueness if the file is already present in the FilesData at the server end.


Loader.
Up arrow icon