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 上上传照片会产生类型错误网络错误
				
        
 
            
        基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
 - navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
 - Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
 - 如何比较两个 NSDate:哪个是最近的? 2022-01-01
 - UIImage 在开始时不适合 UIScrollView 2022-01-01
 - SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
 - iOS - UINavigationController 添加多个正确的项目? 2022-01-01
 - 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
 - Android Volley - 如何动画图像加载? 2022-01-01
 - Play 商店的设备兼容性问题 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				