Skip to content
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

m.request broken for blob data in 2.0.4rc #2392

Closed
CarlLeth opened this issue Mar 8, 2019 · 1 comment
Closed

m.request broken for blob data in 2.0.4rc #2392

CarlLeth opened this issue Mar 8, 2019 · 1 comment

Comments

@CarlLeth
Copy link

CarlLeth commented Mar 8, 2019

Mithril Version: 2.0.4rc

request.js, line 118, initializes the response to xhr.responseText before checking for an "extract" function. But the xhr.responseText getter throws an exception (in Chrome, at least) if the response type is anything other than '' or 'text', such as 'blob'. In 1.1.6, providing an extract function properly prevented mithril from calling the xhr.responseText getter.

Steps to Reproduce

Submit

var blobPromise = m.request({
    url: 'an endpoint returning file or blob data',
    config: xhr => xhr.responseType = 'blob',
    headers: { 'Accept': 'octet/stream' },
    extract: xhr => xhr.response
});

Expected Behavior

The returned promise is fulfilled with the blob data.

Current Behavior

Browser error: "Failed to read the 'responseText' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'text' (was 'blob')."

Possible Solution

Leave response uninitialized on line 118 of request.js. Set it to xhr.responseText before line 125 instead, and change line 123 to response = args.deserialize(xhr.responseText).

Environment

  • Browser: Chrome 71.0.3578.80 (64-bit)
@dead-claudia
Copy link
Member

Duplicate of #2333

@dead-claudia dead-claudia marked this as a duplicate of #2333 Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

No branches or pull requests

2 participants