-
Notifications
You must be signed in to change notification settings - Fork 838
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
How to manage responseType = 'blob' #479
Comments
Do you know how to do this with |
It should actually work from Angular 1.2.5 and above :) angular/angular.js#1013 What angular version are you using? |
With 1.2.5, you should be able to do: Restangular.one('attachments', idAtt).get({}, {"X-Auth-Token": 'token'}).then(function(response) {
// Response is the blob :)
}); |
Let me know if it does :) |
Thank you for your prompt answer! Here is the $http solution :
But can't find in the restangular documentation where to define the responseType attribute ^^ |
In fact, the solution that you've suggested doesn't work because the response is not a blob (that is why it is necessary to put the additional attribute responseType: 'blob' with the $http solution) |
Then do: Restangular.one('attachments', idAtt).withHttpConfig({responseType: 'blob'}}.get({}, {"X-Auth-Token": 'token'}).then(function(response) {
var url = (window.URL || window.webkitURL).createObjectURL(response);
window.open(url);
}); |
Did that work? |
Thank you for the answer! I'm currently at work, let me try this this evening (in 12hours) ;) |
I guess you will not be surprised if I tell you that everything works fine ;) |
That's awesome :).
|
How to set the appropriate MIME type? Right now showing as 'application/unknown' with some very strange file name. |
In my case, response type is not |
@vishwajeetv : stuck on the same problem. Any heads up ?? |
responseType is just what the type the response should be in your JS. Blob is for everything binary like a pdf or image. You can download it for example by constructing a link with |
In my case |
blob would work but I use arraybuffer to be able to decoded error response to json if any
|
you also can use the paket "angular-file-saver" and use it in the "then block":
type depends on your case: excel, pdf, etc. |
Using
|
I 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 :
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?
The text was updated successfully, but these errors were encountered: