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

Infer responseType from response headers? #793

Closed
reid3290 opened this issue Mar 26, 2017 · 3 comments
Closed

Infer responseType from response headers? #793

reid3290 opened this issue Mar 26, 2017 · 3 comments

Comments

@reid3290
Copy link

I wanted to use axios to download a image from the server. At the beginning I try to do this:

axios.get(url).then(response=>fs.writeFile(filename, response.data));

But obviously the image downloaded is broken. Then I toke a lot of time to go over the whole document and figure it out I have to set the responseType manully:

axios.get(url,{
    responseType: 'stream'
}).then(response=>response.data.pipe(fs.createWriteStream(filename)));

Is there any chance that axios can figure reponseType out automatically?
If it can't, I think it's better to make it more clear in the doc(expecially what does stream mean, as well as blob and buffer).

Thx

@evseevnn-zz
Copy link

same problem

@realdubb
Copy link

realdubb commented Nov 9, 2018

This would be awesome!! I'm having an issue where an API sends json on error and binary data on success so I'm having issues with axios automatically encoding the json in arraybuffer despite content-type being application/json - https://stackoverflow.com/questions/53230205/change-responsetype-in-axios-based-on-response

@chinesedfan
Copy link
Collaborator

Closed in favor of #811.

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants