How to manage responseType = 'blob'
See original GitHub issueI call an API endpoint that returns a file. As you can see below, I success to implement a full javascript snippet to download the file using xhr :
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open('GET', Restangular.one('attachments', idAtt).getRestangularUrl(), true);
xhr.setRequestHeader('X-Auth-Token', 'token');
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
var blob = this.response;
var url= window.URL.createObjectURL(blob);
window.open(url);
}
};
xhr.send();
But now, I would like to use only Restangular instead! However, it doesn’t seem to be possible setting the responseType to ‘blob’… I’ve tried to convert the text response to blob, but I finally get a corrupted file at the end. Has someone already solved this kind of problem?
Issue Analytics
- State:
- Created 10 years ago
- Comments:19 (7 by maintainers)
Top Results From Across the Web
How to handle error for response Type blob in HttpRequest
I am calling an http request using httpClient and using response Type as 'blob' but the problem is when it ...
Read more >Response.blob() - Web APIs - MDN Web Docs
The blob() method of the Response interface takes a Response stream and reads it to completion. It returns a promise that resolves with...
Read more >Handle Blobs requests with Axios the right way - Medium
The most tricky part here is to change the responseType . We don't want to get a response with Content-Type: application/json which is...
Read more >response.blob - You.com | The Search Engine You Control
Note: If the Response has a Response.type of "opaque", the resulting Blob will have a Blob.size of 0 and a Blob.type of empty...
Read more >HttpRequest - Angular
withCredentials: boolean, Read-Only. Whether this request should be sent with outgoing credentials (cookies). ; responseType: 'arraybuffer' | 'blob' | 'json' | ' ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
blob would work but I use arraybuffer to be able to decoded error response to json if any
Then do: