"无法识别的FormData部分。"使用XMLHttpRequest进行React本机(android)视频上传时出错

时间:2017-06-07 06:56:12

标签: javascript android react-native xmlhttprequest cloudinary

我正在尝试将视频上传到cloudinary,以下代码适用于ios但在上传开始时几乎立即在Android上收到错误,错误为Unrecognized FormData part.

let {api_key, api_secret, cloud_name, url} = CLOUDINARY_CONFIG;
let timestamp = (Date.now() / 1000 | 0).toString();
let hash_string = `eager_async=true&folder=${endpoint}&timestamp=${timestamp}&use_filename=true${api_secret}`;
let signature = CryptoJS.SHA1(hash_string).toString();
let formData = new FormData();
formData.append('timestamp', timestamp);
formData.append('api_key', api_key);
formData.append('signature', signature);
formData.append('eager_async', true);

formData.append('file', {uri: body.uri, type: 'video/mp4', name: `video_${timestamp}.mp4`});
formData.append('eager', [{width: 720}]);

formData.append('folder', endpoint);
formData.append('use_filename', true);
let xhr = new XMLHttpRequest();
xhr.open('POST', url);

xhr.onerror = (event) => {
next(actionWith({
  type: failureType,
  params
}));
};

xhr.send(formData);

最初,body.uri路径无效,且前缀为file://

1 个答案:

答案 0 :(得分:0)

找到解决方案,问题不是设置iOS上出于某种原因工作的宽度。

删除行formData.append('eager', [{width: 720}]);解决了问题。