I'm trying to convert an uri image (retrieved with react-native-image-picker) to an array buffer to upload the file to s3 (since s3 does not support form-data for put requests I can't use it)
this is my code
let fetched = await fetch(pictureInfo.uri)
console.log("Fetched uri:", fetched)
let arrayBuffer = await fetched.arrayBuffer()
but running it I receive
Error: FileReader.readAsArrayBuffer is not implemented
How can I convert it to a buffer and upload to s3 without converting it to base64?
Without going for the base64 method, you can upload the image file directly using the react-native-fetch-blob
package.
Assuming that you have aws-sdk
for react-native
// Add Config
AWS.config.update({
region: // Your Region,
accessKeyId: // Your Access key,
secretAccessKey: // Your Secret Key,
sessionToken: // Your Session Token,
});
// Initialize
const s3 = new AWS.S3();
// Get Signed Url
const signedUrl = await s3.getSignedUrl('putObject', {
Bucket: // Your Bucket,
Key: // Your Key,
ContentType: // Content Type, example `image/jpg`,
});
const s3 = new AWS.S3();
const upload = await RNFetchBlob.fetch('PUT', signedUrl, {
'Content-Type': // Content Type
}, RNFetchBlob.wrap(localPath)); // where local path would be your local image path ${image.uri}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With