• Home
  • Jobs
  • Courses
  • Questions
  • Teachers
  • For business
  • ES/EN

0

51
Views
How do make post request with Axios and sending the files data in `Files` rather than in the body content?

I'm looking at trying to write a JavaScript function to post data back to my API server with Axios. However, I need the file to be in the Files field of the request and not in the body.

let formData  = new FormData();
formData.append("files", acceptedFiles[0], 'image.jpeg');
let url = "https://webhook.site/39e22a22-7fe2-45e6-bf7b-ba406ea550cc"
let resp = await axios.post(url, formData,{
   headers: { 'content-type': 'multipart/form-data' }
});

Raw Content Received by webhook.site

------WebKitFormBoundaryu1izASXZlBjTDNFk
Content-Disposition: form-data; name="files"; filename="image.jpeg"
Content-Type: image/jpeg

enter image description here

But when I do it with something like Insomnia API client. I get no body and no content. But the file is in the Files part of the request.

enter image description here

How do I achieve the what Insomnia is doing?

about 1 month ago ·

Santiago Trujillo

Answer question
Find remote jobs
Loading

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2022 PeakU Inc. All Rights Reserved.