I have a buffer of an image like:
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 04 03 03 03 03 02 04 03 03 03 04 04 04 05 06 0a 06 06 05 05 06 0c 08 09 07 ... 231835 more bytes>
and I have installed form-data module from npm.
I need to send this image file as form-data, I tried:
const form = new FormData();
form.append("image", buffer, { filename: "london.jpg" });
But it didn't work, how can I solve this problem?
I finally found a way to resolve the issue by using request module. https://www.npmjs.com/package/request
request.post({
url,
formData: {
image: {
value: file.buffer, // Give your node.js buffer to here
options: {
filename: file.originalname, // filename
contentType: file.mimetype // file content-type
}
}
}
},(error, http_response, body) => {
});