问题描述
我正在使用 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 上上传照片会产生类型错误网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!