Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDIT] Support POSTing binary data to another API using gaxios #348

Open
arjunk-pki opened this issue Oct 12, 2020 · 3 comments
Open

[EDIT] Support POSTing binary data to another API using gaxios #348

arjunk-pki opened this issue Oct 12, 2020 · 3 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@arjunk-pki
Copy link

arjunk-pki commented Oct 12, 2020

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]
@sofisl sofisl added the type: question Request for information or clarification. Not an issue. label Oct 12, 2020
@mpiorowski
Copy link

I have the same question. Two years in development and no answer :/ No idea how to send files using gaxios.

@bcoe bcoe added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Jun 10, 2022
@bcoe bcoe changed the title How to POST binary data to another API using gaxios [EDIT] Support POSTing binary data to another API using gaxios Jun 10, 2022
@bcoe
Copy link
Contributor

bcoe commented Jun 10, 2022

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.

@velsietis
Copy link

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 f844222)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

6 participants