JakeChampion / fetch

A window.fetch JavaScript polyfill.
MIT License
25.76k stars 2.84k forks source link

File fetching broken since commit 0c1d2b9 #1371

Closed ldaudet closed 1 year ago

ldaudet commented 1 year ago

Hi there!

Thanks a lot for the work on this library! I am using it in a react native app to run code like this: https://snack.expo.dev/@bacon/documentpicker-to-blob (line 24), to grab an image file that I will then upload to the backend.

This worked for the longest time, but after uploading to the latest version of expo, it also uploaded the version of react native, which in turned updated our version of fetch. The problem is that with the latest version of fetch, the fetch of file doesn't work anymore, as described here: https://github.com/facebook/react-native/issues/38625#issuecomment-1651430009

After looking at the code, I realized that the issue was actually do to the work on commit 0c1d2b9 where you added a check for the return code to be between certain values:

  if (this.status < 200 || this.status > 599) {
    throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].")
  }

When removing this check, everything works just fine with fetching the file, even with the lastest version of fetch, as the fetch of the a file return a status 0.

Would it be possible to either remove the check, or update the code to get a 200 status on successfully fetching a file?

Thanks a lot

mercpls commented 1 year ago

@ldaudet Still waiting on a response but there is a PR based on this suggestion now.

meteorlxy commented 1 year ago

According to fetch spec - Schema fetch:

"file" For now, unfortunate as it is, file: URLs are left as an exercise for the reader.

When in doubt, return a network error.

I'm not sure what's the exact meaning of the spec - Should fetch support file uri or not?

Any native speaker or spec expert could help answer it? 🤔

JakeChampion commented 1 year ago

Fixed via #1375 👍