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

can-ajax does not handle blob response types #66

Open
mikemitchel opened this issue Jun 20, 2019 · 1 comment
Open

can-ajax does not handle blob response types #66

mikemitchel opened this issue Jun 20, 2019 · 1 comment

Comments

@mikemitchel
Copy link
Contributor

I have a use case where I expect the response to be a binary blob file (actual response Content-Type: application/pdf), and am able to make it work with this code (where showFile handles processing and downloading the returned blob/file):

    canAjax({
      url: assembleUrl,
      data: assembleData,
      type: 'post',
      contentType: 'application/x-www-form-urlencoded',
      dataType: null,
      xhrFields: {
        responseType: 'blob' // pdf file
      }
    }).then((xhrObj) => {
      // blob file is on xhr.response
      showFile(xhrObj.response)
    })

This works despite xhrObj.responseText showing:

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

This code/switch statement should be updated to handle binary file response types, probably just returning xhr.response instead of the whole object:

can-ajax/can-ajax.js

Lines 112 to 114 in c4e4c26

if(type && (xhr.responseText || xhr.responseXML)){
switch (type) {

@mikemitchel
Copy link
Contributor Author

@phillipskevin please review to add anything I might have missed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant