Changing order form data in upload file

Hi Team,

Is it possible to append uploadFiles at the bottom after form data when sending REST API to upload  files to API?

As per current order,

* Upload files

* Path

* action

* save 

expected order 

* path 

* action

* save 

* upload files


As i want to retrieve form fields first from request body to create directory at the server before storing the file. Kindly advise if it is possible




3 Replies 1 reply marked as answer

IL Indhumathy Loganathan Syncfusion Team September 6, 2021 12:53 PM UTC

Hi Sathiya, 
 
Greetings from Syncfusion support. 
 
We have validated your requirement in File Manager component. We have used the Uploader component internally for File Manager upload operation. We have formed the upload request internally which will be the default format of upload request for our component. 
 
However to achieve your requirement, we have overridden the source method named “uploadFilesRequest” to append the custom form data after original form data in the request. We have used the created event to call internal method where we modified the Form Data order and updated it. 
 
Refer to the below code. 
 
onCreated() { 
    (Uploader as any).prototype.uploadFilesRequest = function(selectedFiles, i, custom) { 
      var _this = this; 
      var cloneFiles = []; 
      var chunkEnabled = this.checkChunkUpload(); 
      var ajax = new Ajax(this.asyncSettings.saveUrl, 'POST', true, null); 
      ajax.emitError = false; 
      var getFileData; 
      if (this.isServerBlazor) { 
        getFileData = selectedFiles.slice(0); 
        cloneFiles.push(getFileData[i].rawFile); 
      } 
      var eventArgs = { 
        fileData: this.isServerBlazor ? getFileData[i] : selectedFiles[i], 
        customFormData: [], 
        cancel: false, 
        currentRequest: null 
      }; 
      var formData = new FormData(); 
      ajax.beforeSend = function(e) { 
          …… 
          if (eventArgs.cancel) { 
            _this.eventCancelByArgs(e, eventArgs, selectedFiles[i]); 
          } 
          //Custom Form Data 
          var customFormDatas = [ 
            { path: eventArgs.customFormData[0].path }, 
            { action: eventArgs.customFormData[1].action }, 
            { data: eventArgs.customFormData[2].data } 
          ]; 
          eventArgs.customFormData = customFormDatas; 
          //Update Form Data 
          _this.updateFormData(formData, eventArgs.customFormData); 
        }); 
        var name_5 = this.element.getAttribute('name'); 
        formData.append( 
          name_5, 
          selectedFiles[i].rawFile, 
          selectedFiles[i].name 
        ); 
        …… 
         ajax.send(formData); 
        } 
      } 
    }; 
  } 
 
 
You can find the sample demonstrating the solution below. 
 
 
 
Output Screenshot: 
 
 
 
 
Similar to the above way, you can change the order based on your requirement. 
 
Please let us know if you need any further assistance. 
 
Regards, 
Indhumathy L 


Marked as answer

SA sathiya replied to Indhumathy Loganathan September 6, 2021 07:05 PM UTC

Highly appreciated it.  it works perfectly for my requirement. thanks a lot. 



KR Keerthana Rajendran Syncfusion Team September 7, 2021 05:25 AM UTC

Hi Sathiya, 
 
Most welcome. We are glad to hear that the provided suggestions helped you. Please get back to us if you need any further assistance. 
 
Regards, 
Keerthana R. 


Loader.
Up arrow icon