-
Notifications
You must be signed in to change notification settings - Fork 4
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
undefined
in response.body when responseType is 'blob' or 'arraybuffer'
#12
Comments
The post method paramater should be: When xior.get('https://exmaple.com/some/api', null, {responseType: 'blob'}).then(res => {
console.log(res.response)
}); Same with fetch's response: fetch('https://exmaple.com/some/api').then(response => {
console.log(response)
}); BTW, what you want do with this blob? if you want download pdf, you can: // For browser
xior
.post(
'http://assets.xxxxx.org:3000/uploads/3ba6921c-031e-426b-94a3-a4b966fc145f/documents/0f6a1d1166.pdf',
null,
{
headers: {
Accept: 'application/pdf',
},
responseType: 'blob',
}
)
.then((res) => res.response.blob())
.then((blob) => {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'filename.pdf';
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove(); //afterwards we remove the element again
}); For nodejs: |
Thank you for your response. Yes, I am passing the options as the third argument, let me see if I can get a public URL I can use as a production. This is what I am currently doing, I just wanted to bring your attention to it in case it's a bug 🐛
|
Currently, xior just return the original fetch response when And I update the README. Thank you for report this 🙌 |
Yeah, it will be a little confuse, I will reopen this issue, and fix in next version. Again, thanks for the feedback! |
Thank you, suhaotian |
Also, I'll like to make this contribution. |
@Aybee5 Welcome contribution! It's Here: https://github.com/suhaotian/xior/blob/main/src%2Fxior.ts#L319 |
Merged then the issue automatic closed! (well done, github!) |
When I set the responseType: 'blob' for a request, the response.body is undefined, similar to the following axios issue
axios/axios#1392
Example something like this
The text was updated successfully, but these errors were encountered: