[EDIT] Support POSTing binary data to another API using gaxios
I'm using gaxios NPM library. I've an external service that accepts application/octet-stream as media type. I need to send a binary data from my Node.JS application to this server. How to do this ?. Whenever I try to send a binary data by converting it to Buffer, that external service throws media type application/json is not supported error. I think, gaxios internally serializes body into application/json. Please see my following code snippet.
const bufferData = Buffer.from(jsonObject.data)
I have to send this binary data using gaxios.
public async postBinaryData(data:Buffer) : Promise<any>{
const requestOptions: GaxiosOptions = {};
requestOptions.url = 'http://localhost/api/acceptBinary'; // External Service
requestOptions.method = 'POST';
requestOptions.headers['Content-Type'] = 'application/octet-stream'; // Should we add this ? It's not overriding default request mime type.
const gaxiosResponse = await request(requestOptions);
}
When I used this, I got the below WARN.
Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json' not supported]
I have the same question. Two years in development and no answer :/ No idea how to send files using gaxios.
I'm updated this to reflect the fact that we don't support this functionality today, and should potentially consider adding this feature as an improvement to the library.
I might have misunderstood the issue, but I got it working ok for me.
I used:
...
data: fs.createReadStream(filename),
headers: {
'Content-Type' : 'application/octet-stream'
}
...
as explained in the README file (see f8442221c9e107cddb78122707e1e75f5d0e6b05)