Answer the question
In order to leave comments, you need to log in
How to correctly compose the request body with multipart / form-data?
I want to manually send a file, an example of a request body part:
Content-Disposition: form-data; name="myfile"; filename="pic.jpg"
Content-Type: image/jpeg
(пустая строка)
содержимое файла
Answer the question
In order to leave comments, you need to log in
https://learn.javascript.ru/formdata
or do you want it manually? Then the easiest option is through the blob constructor
const body = new Blob(['some text', file, 'some text 2', ...]);
Here's an option right out of the box
const formData = new FormData();
formData.append('file', document.querySelector('input[type=file]').files[0]);
fetch('http:google.com', {
body:formData,
'POST',
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question