我正在尝试将视频上传到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}×tamp=${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://
答案 0 :(得分:0)
找到解决方案,问题不是设置iOS上出于某种原因工作的宽度。
删除行formData.append('eager', [{width: 720}]);
解决了问题。