question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure xhr.responseType on request for binary data

See original GitHub issue

I 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:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fehguycommented, Dec 4, 2014

i propose we keep this in the swagger-ui issue #374

0reactions
fehguycommented, Nov 26, 2016

added long ago

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found