I want to pass data in Body for all POST save call when uploading a file in Uploader component

I want to pass data in Body for all POST save call when uploading a file in Uploader component


1 Reply

PM Ponmani Murugaiyan Syncfusion Team March 15, 2022 02:28 AM UTC

Hi Rahul, 

As per the requirement we have created sample using the ajax call for handler and along with you can pass any headers or other bits of information needed in this request. Also, we would like to let you know, while you are using the ajax request for saving operation, you have to pass formData as given below. 

[app.component.html] 

<ejs-uploader #defaultupload id='defaultfileupload' [autoUpload]="false" (created)='onCreate($event)'  
    (progress)='onUploadInProgress($event)' (selected)='onSelected($event)' [dropArea]='dropElement'>  
</ejs-uploader> 

[app.component.ts] 
 
public onSelected(args) { 
    setTimeout(() => { 
      document.getElementsByClassName('e-file-upload-btn')[0] 
        .addEventListener('click', this.UploadClick.bind(this)); 
    }, 50); 
  } 
public UploadClick() { 
    var data = new FormData(); 
    data.append('file', this.uploadObj.element.files[0]); 
    $.ajax({ 
        type: 'POST', 
        url: 'https://localhost:44334//Home/Index', 
        data: data, 
        contentType: false, 
        processData: false, 
        success: function (data) { 
        alert(data); 
        }, 
    }); 
} 



Regards, 
Ponmani M 


Loader.
Up arrow icon