BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
Hi,
Hi Viji Palanisamy,
Query1: I need to send uploaded file to my backend using API as multi part data.
Thank you for reaching out us. Certainly! Achieving this can be done through the use of our chunk uploader. I recommend exploring the sample provided below, as it showcases how to seamlessly send uploaded files as multipart data.
Sample: https://stackblitz.com/edit/react-mayr7k-kdoajk?file=index.js
For further insights and detailed guidance, I encourage you to refer to our comprehensive documentation and interactive demo available at the links below
Demo: https://ej2.syncfusion.com/react/demos/#/material3/uploader/chunk-upload
Documentation: https://ej2.syncfusion.com/react/documentation/uploader/chunk-upload
Query2: I need to add X-XSRF-Token to the link to send to api.
Your inquiry has been thoroughly reviewed, and we've taken steps to fulfill your request. We've prepared a sample based on your specifications. To implement this, you can pass the token through the file selected event. Subsequently, you'll be able to retrieve the authorization token within the server save method. Kindly refer to the samples below
Client side
onfileSelect(args) { var accessToken = 'Basic test123'; args.currentRequest.setRequestHeader('Authorization', accessToken); }
|
Server side
[DisableRequestSizeLimit] public void Save(IList<IFormFile> UploadFiles) { var auth = Request.Headers["Authorization"];
var header = HttpContext.Request.Form["Name"]; try { foreach (var file in UploadFiles) { var filePath = @"" + file.Name; if (System.IO.File.Exists(filePath)) {
}
using (var fileStream = new FileStream(filePath, FileMode.Create)) { file.CopyTo(fileStream);
} } } catch (Exception e) { Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.StatusCode = 300; Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload"; Response.Headers.Add("Access-Control-Expose-Headers", "Error"); Response.Headers.Add("Error", "File already exists");
} } |
Client side Sample: https://stackblitz.com/edit/react-hx7uhh-qjwrvw?file=index.js
Regards,
Yohapuja S