【发布时间】:2020-11-13 12:54:31
【问题描述】:
我使用 fetch 将图像发送到服务器。
在 iOS 上,一切都按预期工作,但在 android 上,我得到 Request fialed。
我从 expo 图像选择器获得的 uri,在 IOS 上一切正常。
const form = new FormData();
form.append('file', {
uri: imageUri,
name: 'file.jpg',
fileName: 'file',
});
fetch(api,{
method: 'post',
body: form,
})
.then(response => response.text())
.then(textResponse => {
console.log(textResponse);
Alert.alert(textResponse);
if (textResponse){
setAccuracyResponse(textResponse);
}
})
.catch(error => {
console.error(error)
});
在安卓上我得到这个响应
Network request failed
- node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
Expo sdk v39
世博会版本 3.28.5
节点 v14.15.0
npm 6.14.8
【问题讨论】:
-
嘿,即使我也面临着类似的问题。你有进步吗?
-
@SubhangV 我已经更新了我的答案,请查看下方。
标签: react-native expo