gpt4 book ai didi

android - 网络请求失败在 https 图像上传 Android 上做出 native react

转载 作者:行者123 更新时间:2023-12-04 00:57:38 25 4
gpt4 key购买 nike

我正在尝试通过 fetch api 上传图片但得到 网络请求失败 真实设备android上的错误。
我也尝试了很多来自谷歌的建议,但对我没有任何帮助。

我的依赖是:

"react-native": "0.62.0",
"axios": "^0.19.2",
"form-data": "^3.0.0",
"react": "16.11.0",
"react-redux": "^7.2.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"


我的图片上传 fragment :

const imagePick = () => {
const formData = new FormData();

try {

const options = {
title: 'Select Avatar',
storageOptions: {
skipBackup: true,
path: 'images',
},
};

ImagePicker.showImagePicker(options, (response) => {

formData.append('avatar', {
uri: response.uri,
type: response.type,
name: response.fileName,
})

fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${authToken}`
},
body: formData
})
.then(res => {
console.log(res.status)
})
.catch(e => {
console.log(e)
})

});

} catch (e) {
toast("Unable to upload profile photo")
}
}


我也在使用安全的 https url;

最佳答案

我也面临同样的问题,但我想这个问题与 axios 库无关,而是因为 React Native 本身。

如此处所述,comment ,是因为脚蹼 .

因此,在 React Native 对其进行处理之前,您可以在 MainApplication.java 中提到的下面的行中进行评论

initializeFlipper(this, getReactNativeHost().getReactInstanceManager());

发表评论 , 把//放在上面一行的前面

//initializeFlipper(this, getReactNativeHost().getReactInstanceManager());

关于android - 网络请求失败在 https 图像上传 Android 上做出 native react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61102893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com