Although the HTTP request has content-type: multipart/form-data
, the actual form data also needs to have its content-type
identified, as well as filename in some cases:
POST /my/server/path HTTP/1.1
....
content-type: multipart/form-data; boundary=--------------------------794262681322510475281872
...
Transfer-Encoding: chunked
2fe5b
----------------------------794262681322510475281872
Content-Disposition: form-data; name="image"; filename="my-image.jpg"
Content-Type: image/jpeg
...a bunch of binary data...
The form-data
package infers filename and content-type
from fs.ReadStream
because that information is available in the file that you've read to a stream. With a raw Buffer
or Blob
it's just the raw data and form-data
cannot infer content type, so you need to set it explicitly:
formData.append('image', buffer, {filename: 'image.jpg', contentType: 'image/jpg'});
You need to adapt that to your server's API spec, but that's the general idea. See here for further detail.