I'm uploading audio/image files from my Android phone using react native. I'm using aws-sdk to upload and upload works fine without any problem and I could see those uploaded files on my S3 bucket.
The problem is that, when I download the files that uploaded, it is corrupted or it is in different format.
I've made sure that I'm using the correct ContentType (audio/wav, image/jpeg). However, after downloading the file from S3 bucket, I see the file is of type application/octet-stream as shown below.
What am I missing here? Appreciate any help. Thank you.
import RNFS from 'react-native-fs';
import AWS from 'aws-sdk';
import base64 from 'react-native-base64'
uploadFileToS3 = async (file, fileInfo, details) => {
const BUCKET_NAME = my_bucket
const REGION = my_region
const IAM_USER_KEY = my_key
const IAM_USER_SECRET = my_secret
const s3bucket = new AWS.S3({
accessKeyId: IAM_USER_KEY,
secretAccessKey: IAM_USER_SECRET,
region: REGION,
signatureVersion: 'v4',
});
const contentType = fileInfo.mimeType;
const contentDeposition = `inline;filename="${fileInfo.name}"`;
const fPath = file;
const base64_data = await RNFS.readFile(fPath, 'base64');
const arrayBuffer = base64.decode(base64_data);
return new Promise((resolve, reject) => {
s3bucket.createBucket(() => {
const params = {
Bucket: BUCKET_NAME,
Key: `my_folder/${fileInfo.name}`,
Body: arrayBuffer,
ContentDisposition: contentDeposition,
ContentType: contentType,
};
s3bucket.upload(params, (error, data) => {
if (error) {
reject(error);
} else {
resolve(data);
}
});
});
});
};