javascript - Node.js File Upload doesn't work -
i need post image external service.
if use client postman test upload manually works perfectly.
i have make post
, supply body form-data
, key picture
image.
but doesn't work if i'm posting node app. i'm using request module handling requests.
const formdata = { picture: fs.createreadstream('./path/to/image') } request.post({url: "http://example.com", formdata: formdata}, function(err, res, body) { console.log(body) }
the log says {"code":400,"exception":"the file failed upload.}
since external service can't more information error.
i need replicate request make postman. how it? don't care module use requests.
when sending file consider using stream post action, example:
const options = { method: 'post', url: "www.someurl.com" }; const req = request(options, callback); const form = req.form(); form.append('image', fs.createreadstream(file_path));
is possible sending file before read action finished?
Comments
Post a Comment