qiniudemo / react-native-sdk

Qiniu React Native SDK ,A pure javascript implementation
MIT License
155 stars 37 forks source link

[IOS]调用upLoadFile时,服务器返回400 #27

Closed johnbryant closed 7 years ago

johnbryant commented 7 years ago

rn版本:0.39.2

image

image

johnbryant commented 7 years ago

image

这是formInput里的内容。

acodercc commented 7 years ago

是的,我也遇到这个问题了,请问你解决了吗

buhe commented 7 years ago

@CecilLee 试一下新的版本 3.0

acodercc commented 7 years ago

@buhe xhr也是不可以的,400错误一定会有。

但也不能确定是0.39.2的问题,

400错误是服务端报告的吧

acodercc commented 7 years ago

这个问题应该是qiniu的服务端的问题

buhe commented 7 years ago

未必是服务器问题,是 payload 的问题,这个问题我们定位过了,0.39 有一定几率发送错误的 payload

johnbryant commented 7 years ago

@buhe 表示用了3.0上传没成功过,一直报这个错 image

johnbryant commented 7 years ago

还是用的2.0版本,上传之前把图片压缩了一下,就很少出问题了

chuangbo commented 7 years ago

我是 0.40,大概率遇到 400 错误,偶尔 200 ok

chuangbo commented 7 years ago

应该是 React Native xhr API 的问题,更换为 react-native-fetch-blob 后问题解决。


import Qiniu from 'react-native-qiniu';
import RNFetchBlob from 'react-native-fetch-blob';

/**
 * Use react-native-fetch-blob to fix large file issue
 */
export function uploadFile(uri, token, formInput) {
  if (typeof formInput.type == 'undefined') {
    formInput.type = 'application/octet-stream';
  }

  if (typeof formInput.name == 'undefined') {
    var filePath = uri.split("/");
    if (filePath.length > 0) {
      formInput.name = filePath[filePath.length - 1];
    } else {
      formInput.name = "";
    }
  }

  return RNFetchBlob.fetch('POST', Qiniu.Conf.UP_HOST, {
    'Content-Type' : 'multipart/form-data',
  }, [
    { name: 'file', filename: formInput.name, type: formInput.type, data: RNFetchBlob.wrap(uri)},
    { name : 'key', data : formInput.key},
    { name : 'token', data : token},
  ]);
}
jlala commented 7 years ago

@johnbryant 上传之前把图片压缩 在rn里面用了什么组件 压缩的?

jlala commented 7 years ago

你们 使用七牛 rn版本 上传图片速率是多少?

johnbryant commented 7 years ago

@jlala react-native-image-resizer

iOSHw commented 7 years ago

up是不准备更新这个bug了吗?最佳解决方案是什么? @buhe