Photo upload on React Native Android produce Type Error Network Error(在 React Native Android 上上传照片会产生类型错误网络错误)
问题描述
我正在使用 fetch API 执行照片上传,但我不断收到 Type Error Network Request Error.我在模拟器和设备上收到相同的错误.我使用 react-native-image-crop-picker 作为照片上传数据的来源.有什么想法吗?
I'm executing a photo upload using the fetch API and I keep receiving Type Error Network Request Error. I receive the same error on the emulator and a device. I'm using react-native-image-crop-picker as the source for the photo upload data. Any thoughts?
const handlePhotoUpload = async (image: any, token: string) => {
const { path, filename, mime } = image;
const uri = path.replace("file://", "")
const file = {
uri,
type: mime,
name: filename
};
const body = new FormData()
body.append('file', file)
const config = {
method: 'POST',
headers: { 'Authorization': 'Bearer ' + token },
body
};
return await fetch(`${<API URL>}/user/photo`, config)
}
推荐答案
我遇到了同样的问题,它发生在 Android 中,但在 IOS 中运行良好.一世猜猜这个关于 Flipper Network 的问题.
I faced same issue, it happens in Android, but works well in IOS. I guess this issue about Flipper Network.
有一段时间,我评论了initializeFlipper(this, getReactNativeHost().getReactInstanceManager())
For while, I commented initializeFlipper(this, getReactNativeHost().getReactInstanceManager())
在这个文件中/android/app/src/main/java/com/{your_project}/MainApplication.java
这篇关于在 React Native Android 上上传照片会产生类型错误网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 React Native Android 上上传照片会产生类型错误网络错误
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
