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

Getting local files (file://) fail after upgrading from 0.18.0 to 0.19.0 #2416

Closed
tobias-rahm opened this issue Sep 16, 2019 · 1 comment
Closed

Comments

@tobias-rahm
Copy link

Describe the bug
When using axios to get a local file (file://...) I get status code 0 as if there's a CORS issue. This didn't happen using version 0.18.0 so I assume that this is a bug?

To Reproduce
Get a local file. In my case I wanted to get a PDF as an array buffer.

axios("file://...", {
    responseType: 'arraybuffer'
    headers: {
        Accept: 'application/pdf'
    }
}).then(..)

Expected behavior
Just like in version 0.18.0 version I should get a 200 response.

Environment:

  • Axios Version 0.19.0
  • OS: Windows 10
  • Browser: EO Webbrowser (Chromium)
  • Browser Version: 19.1.95 (Chromium ~70)
  • Additional Library Versions: React 16.8.6

Additional context/Screenshots
Need to build and run index.html locally so you're making the request from file:// as well.

Alanscut added a commit to Alanscut/axios that referenced this issue Oct 17, 2019
Alanscut added a commit to Alanscut/axios that referenced this issue Oct 17, 2019
@Alanscut
Copy link
Collaborator

The success status code of the file:// protocol is 0, and the default success status code of axios is 200~300. You can customize the validateStatus function to change the success status code to access the local file.

validateStatus: function (status) {
    return status ===0 || (status >= 200 && status < 300); 
  }

Alanscut added a commit to Alanscut/axios that referenced this issue Oct 18, 2019
@Alanscut Alanscut mentioned this issue Nov 20, 2019
chinesedfan pushed a commit that referenced this issue Mar 23, 2020
* fix issue #2416, #2396

* fix Eslint warn

* Modify judgment conditions

* add unit test

* update unit test

* update unit test
@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants