Android上上传照片会产生Type

Android上上传照片会产生Type

本文介绍了在React Native Android上上传照片会产生Type Error Network Error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用访存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)

}

推荐答案

一段时间以来,我发表了评论initializeFlipper(this,getReactNativeHost().getReactInstanceManager())

For while, I commentedinitializeFlipper(this, getReactNativeHost().getReactInstanceManager())

在此文件中/android/app/src/main/java/com/{your_project}/MainApplication.java

这篇关于在React Native Android上上传照片会产生Type Error Network Error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 19:55