小编Moh*_*lah的帖子

网络请求失败对 https 图像上传 Android 做出本机反应

我正在尝试通过 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"

Run Code Online (Sandbox Code Playgroud)

我的图片上传片段:


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: …
Run Code Online (Sandbox Code Playgroud)

android fetch react-native multipath

3
推荐指数
1
解决办法
2296
查看次数

标签 统计

android ×1

fetch ×1

multipath ×1

react-native ×1