更新后,expo react-native获取本地文件不起作用

时间:2018-11-09 09:19:29

标签: android reactjs react-native fetch expo

Expo SDK v.31.0.0 我正在获取localfile来创建Blob。

const response = await fetch(uri)

uri是这样的:“ file:///data/user/0/host.exp.exponent/files/..../rec_1541692353037.m4a”

这在Expo Sdk 30.0.0中非常有效。升级到v.31后,我在Android上遇到错误:

Network request failed

Stack trace:
  node_modules\react-native\Libraries\vendor\core\whatwg-fetch.js:504:29 in onerror
  node_modules\event-target-shim\lib\event-target.js:172:43 in dispatchEvent
  node_modules\react-native\Libraries\Network\XMLHttpRequest.js:578:29 in setReadyState
  node_modules\react-native\Libraries\Network\XMLHttpRequest.js:392:25 in __didCompleteResponse
  node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:191:12 in emit
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:349:47 in __callFunction
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:106:26 in <unknown>
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:297:10 in __guard
  node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:105:17 in callFunctionReturnFlushedQueue

在iOS上,一切正常。我已经尝试过axios,但是仍然遇到相同的错误。

1 个答案:

答案 0 :(得分:1)

我也遇到了这个问题,我通过此链接https://github.com/expo/firebase-storage-upload-example/issues/13#issuecomment-437597679

中的函数解决了这个问题

将您的uri放入此函数,该函数将返回blob。