我正在尝试将刚刚创建的视频从React Native上传到S3,并且在将react-native-aws3和react-native-fetch-blob结合起来时遇到了一些困难。
关于上传图片有几个答案,当我稍微调整一下代码时效果很好。关于如何在没有文件路径的情况下正确传递blob(data.uri或data.path将指向无法正确上传的原始文件)以及options
是否正确,我感到困惑
const options = {
keyPrefix: 'video/',
bucket: 'XXXX',
region: 'XXXXX',
accessKey: 'XXXXX',
secretKey: 'XXXX',
successActionStatus: 201
};
uploadImage(data.path) //I call this once the video is done recording.
const uploadImage = (uri, mime = 'application/octet-stream') => {
return new Promise((resolve, reject) => {
const uploadUri = Platform.OS === 'ios' ? uri.replace('file://', '') : uri
const sessionId = new Date().getTime();
let uploadBlob = null;
fs.readFile(uploadUri, 'base64')
.then((blob) => {
uploadBlob = blob;
let file = {
uri: ???, //a bit confused here.
name: "video",
type: mime
}
RNS3.put(file, options)
.then(response => {
if(response.status !== 201) {
console.log(response.body);
}
console.log(response);
})
.catch(err => console.error(err));
})
})
}
使用FormData提到的其他几个答案。我不知道如何使用这些库添加它。