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.

xhr.response is undefined on blob/arraybuffer response type

See original GitHub issue

Trying to get this file with your nodejs xmlhttprequest

$ curl -X GET -I http://localhost/test/foo.bin
HTTP/1.1 200 OK
Date: Wed, 20 Jun 2018 11:58:51 GMT
Server: Apache/2.4.33 (Unix)
Last-Modified: Tue, 19 Jun 2018 18:37:07 GMT
ETag: "6-56f02f8230618"
Accept-Ranges: bytes
Content-Length: 6
Content-Type: application/octet-stream

using the following code:

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

        var xhr = new XMLHttpRequest;
        xhr.open("GET", "http://localhost/test/foo.bin");
        xhr.setRequestHeader("Accept", "application/octet-stream");
        xhr.responseType = "blob";
        xhr.onreadystatechange = function(e) {
                if (xhr.readyState == 4) {
                        console.log(xhr.response);
                        console.log(xhr.responseText);
                }
        };      
        xhr.send();

Result is undefined for the logline with xhr.response and correct value in xhr.responseText.

Does your module only work for text?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

1reaction
marlinilramcommented, Jul 4, 2018

Hi @nolash I met the same problem here, do you have any work around now?

0reactions
bksubhuticommented, Sep 8, 2020

i’m just using the node library for file reads now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting BLOB data from XHR request - Stack Overflow
responseType = 'arraybuffer'; // Process the response when the request is ready. xhr.onload = function(e) { if (this.status == 200) ...
Read more >
this.response is undefined when responseType is a Blob ...
Hi I've tested this plugin in my case, a file object with a file url (from upload) and creating a Blob file of...
Read more >
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 >
fetch() - The Vanilla JS Toolkit
'undefined' ? factory(exports) : typeof define === 'function' && define.amd ... _bodyBlob.type) { this.headers.set('content-type', this._bodyBlob.type); } ...
Read more >
XMLHttpRequest JavaScript API - JavaScripture
responseType = 'arraybuffer'; request.open('GET', '/'); request.onload = function() { console.log(request.response); console.log(request.response.
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