Answer the question
In order to leave comments, you need to log in
How can I upload a file using form-data that has the body specified as a string?
When I try to upload a file to mysite.com/upload like this, that site thinks the body is empty:
const FormData = require('form-data');
const form = new FormData();
form.append('file', 'file content');
form.submit('http://mysite.com', (err, res) => {
...
});
const fs = require('fs');
const FormData = require('form-data');
const form = new FormData();
form.append('file', fs.createReadableStream('path/to/file'));
form.submit('http://mysite.com', (err, res) => {
...
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question