我正在使用rnfetchblob将视频从我的移动设备上传到API。这是我从rnfetchblob文档复制的代码。
RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
// dropbox upload headers
Authorization : "Bearer access-token...",
'Dropbox-API-Arg': JSON.stringify({
path : '/img-from-react-native.png',
mode : 'add',
autorename : true,
mute : false
}),
'Content-Type' : 'application/octet-stream',
// Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://`.
// Or simply wrap the file path with RNFetchBlob.wrap().
}, RNFetchBlob.wrap(PATH_TO_THE_FILE))
.then((res) => {
console.log(res.text())
})
.catch((err) => {
// error handling ..
})
我与两个术语感到困惑1.path_to_the_the_file如何在我的手机上找到视频的路径。什么是path_to_the_file
我不确定您的尝试方式,但是在选择图像后,我用formdata做到了,并且对于视频,它应该使用相同:
const data = new FormData();
data.append('photo', {
uri: this.state.uri,
type: 'image/jpeg', // or photo.type
name: 'testPhotoName'
});
fetch('https://xx/react_uploadpic', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
body: data,
}).then((response) => console.log(response)).catch((error) => {
console.log(error)
});