itinance / itinance/react-native-fs

Uploading picked mp3 file to aws s3

Open
#883 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

So basically I'm trying upload mp3 files read using this library to s3 buckets, but it seems like there's something wrong with encoding and I'm wondering if it is because I'm making some kind of stupid mistake or because of the library. Mp3 files are no longer playable after upload, ofc I used base64 as mentioned in documentation, but it doesn't work anyway. The part when I'm reading file seems like the one where something may work incorrectly.

````
try {
const results = await DocumentPicker.pick({
type: [DocumentPicker.types.audio],
})

console.warn('res : ' + JSON.stringify(results))
console.warn('URI : ' + results.uri)
console.warn('Type : ' + results.type)
console.warn('File Name : ' + results.name)
console.warn('File Size : ' + results.size)

AWS.config.update({
region: '',
})

const creds = new AWS.CognitoIdentityCredentials({
...
})

AWS.config.credentials = creds

const s3 = new AWS.S3({
apiVersion: '2006-03-01',
params: { Bucket: 'bucket', ContentType: 'audio/mp3' },
})

const base = await RNFS.readFile(results.uri, 'base64')
const buffer = base64.decode(base)
var uploadParams = {
Bucket: 'bucket',
Key: `key`,
Body: buffer,
ContentType: 'audio/mp3',
}
s3.upload(uploadParams, (err: Error, data: ManagedUpload.SendData) => {
if (err) {
console.warn('callback error')
console.warn(err)
} else {
console.warn(data)
}
})`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.