react-native: Response#arrayBuffer throws `FileReader.readAsArrayBuffer` is not implemented on iOS or android
Description
See title. For example:
const response = await fetch('https://sheetjs.com/pres.numbers');
const data = await response.arrayBuffer();
Related issues:
- #20091 and #21209 were closed and locked because “it does not appear to follow any of the provided issue templates”.
- #30769 is an inefficient pure-JS attempt to address the situation. The ideal solution would not involve the intermediate Base64 step.
Version
0.69 (latest)
Output of npx react-native info
n/a (reproducible in Expo Snack)
Steps to reproduce
Load https://snack.expo.dev/DsZd8Av6-?platform=android and test in the “iOS” and “android” platforms. The demo does work in the web platform, in case you want to see the expected output.
Snack, code example, screenshot, or link to a repository
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 21 (3 by maintainers)
Commits related to this issue
- FileReader#readAsArrayBuffer (#36332) Summary: Fixes a number of issues with third party libraries that use `Blob#arrayBuffer` or `FileReader#readAsArrayBuffer`, including https://github.com/facebook... — committed to facebook/react-native by SheetJSDev 4 years ago
- FileReader#readAsArrayBuffer (#36332) Summary: Fixes a number of issues with third party libraries that use `Blob#arrayBuffer` or `FileReader#readAsArrayBuffer`, including https://github.com/facebook... — committed to OlimpiaZurek/react-native by SheetJSDev 4 years ago
It’s crazy that this isn’t supported. I’ve been trying to find a way around this all day.
Not sure what their reasoning is for not approving the PR?
Not stale.
Still an issue in the latest version (
0.70.6), but the offending code is in JS and can be effortlessly patched.The changes from #30769 work when applied to
node_modules/react-native/Libraries/Blob/FileReader.js. For CI use,patch-packagecan automate this process.react-native+0.70.6.patch
Download the linked patch file and save it to
patches/react-native+0.70.6.patchwithin your project and runnpx patch-package.This can be verified on macOS using the original demo app:
@Slapbox please test this in your application.
will react native get ArrayBuffer support???
I guess wget magic only gets you so far. I really need this to work so I’ll post any solution I find. Godspeed, everyone.
Expo does not hide the react-native dependency. From scratch:
This runs in the iOS simulator.
Replace
App.jswith:You will see the error “FileReader.readAsArrayBuffer is not implemented”
Testing today, the package.json dependencies include
expo 48.0.4andreact-native 0.71.3. The patch for that version is: react-native+0.71.3.patchTo use this:
That should patch react-native and you should see “652655 bytes fetched”