Member-only story
How to upload multiple images to AWS S3 in react-native App — Part 2
In my previous article, I explained how to get multiple images using react-native-image-crop-picker
, and in this post, I'll cover how to upload those images to the AWS S3 server.
For that I used react-native-aws3
, this library has no native dependencies so I preferred it over others libraries.
Install react-native-aws3
Please go through their website to install and set IAM’s policy as mentioned.
Upload button and onPress
Now I created a simple button like this
<Button
onPress={onUploadClick}
title="Upload"
/>
as react-native-aws3
upload a single image to S3 at a time but I have multiple images to upload so I used Promise.all
.
const uploadButtonClick = () => {
let promises = [];
images.map((image, i) => {
promises.push(uploadImageToS3(image));
});
}
Here I created an empty array of promises to store each response of the upload call. Next, I am mapping images array to upload calls with a single image and promises.push
is saving that response in promises array.