I am trying to upload video that was just created to S3 from React Native and am having some difficulties combining react-native-aws3 and react-native-fetch-blob.
There are several answers about uploading images, which works fine when I tweak the code a bit. I am confused both about how to properly pass the blob without a file path (data.uri or data.path will point to the original file which won't be uploaded properly) and about whether the options are correct.
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));
})
})
}
Several other answers mentioned using FormData.I don't see how I would add that using these libraries.