Upload images from local machine to Amazon S3

0 votes

I am developing an application and trying to upload an image stored on the device to S3. I know the path to the image but when I try to upload the image, S3 returns an unsupported file error or uploads the file with its name but the file only contains the file path string.

I am using aws-amplify to establish these connections.

Here is the code block that I use:

 const file = `${RNFetchBlob.fs.dirs.DocumentDir}/${localFilePath}`;
 Storage.put("localFolder/" + userId + ".jpeg", file)
                .then(result => console.log(result))
                .catch(err => console.log(err))

Thank you soo much

Jan 16, 2019 in AWS by Anjali
• 2,950 points
2,570 views

1 answer to this question.

+1 vote

There's a nice example in the aws-mobile-react-native-starter repo. 

You just need to read the file, and then you can upload it.

return files.readFile(imagePath)
  .then(buffer => Storage.put(key, buffer, { level: 'private', contentType: result.type }))
  .then(fileInfo => ({ key: fileInfo.key }))
  .then(x => console.log('SAVED', x) || x);

To read the file they've used react-native-fetch-blob:

readFile(filePath) {
    return RNFetchBlob.fs.readFile(filePath, 'base64').then(data => new Buffer(data, 'base64'));
}
answered Jan 16, 2019 by disha

Related Questions In AWS

0 votes
1 answer

Upload an image from Android to Amazon S3

Take a look at the Amazon S3 ...READ MORE

answered Sep 21, 2018 in AWS by Archana
• 4,170 points

edited Aug 8, 2019 by Archana 5,129 views
0 votes
1 answer

How To Upload Images to Amazon S3 Using Perl?

That code won't upload the file - it's simply ...READ MORE

answered Mar 15, 2019 in AWS by datageek
• 3,090 points
1,648 views
0 votes
0 answers

Broken image from image upload to Amazon s3 via base64 string

Feb 18, 2022 in AWS by Rahul
• 2,120 points
1,522 views
0 votes
1 answer

Trying to upload data stream in Amazon S3

Try adding the ContentType & ACL in ...READ MORE

answered Jun 28, 2018 in AWS by Cloud gunner
• 4,670 points
2,566 views
0 votes
1 answer

AWS S3 uploading hidden files by default

versioning is enabled in your bucket. docs.aws.amazon.com/AmazonS3/latest/user-guide/….... the ...READ MORE

answered Oct 4, 2018 in AWS by Priyaj
• 58,020 points
5,978 views
–1 vote
1 answer

How to decrypt the encrypted S3 file using aws-encryption-cli --decrypt

Use command : aws s3 presign s3://mybucket/abc_count.png you get ...READ MORE

answered Oct 22, 2018 in AWS by Priyaj
• 58,020 points
5,221 views
0 votes
1 answer

Import my AWS credentials using python script

Using AWS Cli  Configure your IAM user then ...READ MORE

answered Nov 16, 2018 in AWS by Jino
• 5,820 points
2,877 views
0 votes
2 answers
+3 votes
6 answers

How to move files from amazon ec2 to s3 bucket using command line

Hey, 3 ways you can do this: To ...READ MORE

answered Oct 9, 2018 in AWS by Omkar
• 69,220 points
20,054 views
0 votes
1 answer

what php API can be used to upload and download files to Amazon S3

Amazon have a PHPSDK , check the sample code // ...READ MORE

answered Oct 17, 2018 in AWS by Priyaj
• 58,020 points
4,326 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP