【发布时间】:2020-05-18 23:28:43
【问题描述】:
我正在尝试使用 FormData 将我的视频上传到后端服务器。但是在上传视频文件时,我得到的是字符串值而不是后端的视频文件。谢谢
const formData = new FormData();
formData.append('dare_id', `${encrypted_id}`);
formData.append(
'video',
Platform.OS === 'android'
? uri //local video file uri
: uri.replace('file://', ''), //local video file uri
);
fetch(UPLOAD_URL, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${token}`,
Accept: 'application/json',
},
body: formData,
})
.then(res => res.json())
.then(responseJson => {
console.log(responseJson);
})
.catch(error => {
console.log(error, ' error uploading');
});
【问题讨论】:
标签: react-native fetch