Configure xhr.responseType on request for binary data
See original GitHub issueI have an API returning binary data. I’m trying to figure out how to set the xhr.responseType='arraybuffer'
so I don’t get content encoding errors.
/* swagger api... */
myApi.download({filePath: '/path/to/file.txt.gz'}, function(resp) {
/* here resp.data is the binary data, but full of Unicode error/replacement characters */
});
/* alternatively... */
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://api.example.com/download//path/to/file.txt.gz');
xhr.responseType = 'arraybuffer';
xhr.onload = function(resp) {
if (resp.target.readyState === 4) {
var arraybuffer = xhr.response;
// do stuff with arraybuffer...
}
};
xhr.send();
I’ve tried passing in {responseType: 'arraybuffer'}
with the options but without luck. Digging in the source I’m not seeing anything on how to get access to the underlying XHR object.
Thanks in advance for looking!
Regards, Matt.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
XMLHttpRequest.responseType - Web APIs | MDN
The XMLHttpRequest property responseType is an enumerated string value specifying the type of data contained in the response.
Read more >Setting XMLHttpRequest.responseType forbidden all of a ...
The responseType property cannot be set when the XMLHttpRequest is not async, that is, synchronous. Setting the third parameter of open to false...
Read more >Sending and Receiving Binary Data - Web APIs
Receiving binary data using JavaScript typed arrays. The responseType property of the XMLHttpRequest object can be set to change the expected response type...
Read more >XMLHttpRequest: Get blob file and … | Apple Developer Forums
responseType = "blob"; // arraybuffer xhr.onabort = function() ... Assumed that the closest thing to binary is blob, I make the request with...
Read more >XMLHttpRequest - The Modern JavaScript Tutorial
Configure it: GET-request for the URL /article/. ... "arraybuffer" – get as ArrayBuffer (for binary data, see chapter ArrayBuffer, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top 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
i propose we keep this in the swagger-ui issue #374
added long ago