React AWS3
S3FileUpload is libray for upload any type of files to Amazon AWS S3
npm install --save react-s3
Examples Uploading An Image
Uploading to S3
; //Optional Import; const config = bucketName: 'myBucket' dirName: 'photos' /* optional */ region: 'eu-west-1' accessKeyId: 'ANEIFNENI4324N2NIEXAMPLE' secretAccessKey: 'cms21uMxçduyUxYjeg20+DEkgDxe6veFosBT7eUgEXAMPLE' /* Notice that if you don't provide a dirName, the file will be automatically uploaded to the root of your bucket */ S3FileUpload //** OR *// /** * { * Response: { * bucket: "your-bucket-name", * key: "photos/image.jpg", * location: "https://your-bucket.s3.amazonaws.com/photos/image.jpg" * } * } */});
Deleting an existing file in your bucket
In this case the file that we want to delete is in the folder 'photos'
; //Optional Import; const config = bucketName: 'myBucket' dirName: 'school-documents' region: 'eu-west-1' accessKeyId: 'ANEIFNENI4324N2NIEXAMPLE' secretAccessKey: 'cms21uMxçduyUxYjeg20+DEkgDxe6veFosBT7eUgEXAMPLE' const filename = 'hello-world.pdf' /* If the file that you want to delete it's in your bucket's root folder, don't provide any dirName in the config object */ //In this case the file that we want to delete is in the folder 'photos' that we referred in the config object as the dirName S3FileUpload //** OR *// /** * { * Response: { * ok: true, status: 204, message: 'File deleted', fileName: 'hello-world.pdf' * } * } */});
S3 Bucket Policy
Doc: http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
Defaults your bucket to public-read
: http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html
config
bucketName
required - Your S3 bucketdirName
required - Your S3 folderName/dirNameregion
required - Your S3 bucket's regionaccessKeyId
required - Your S3AccessKeyId
secretAccessKey
required - Your S3SecretAccessKey
Versions History
Version 1.3.0 - Support for any type of file
Version 1.2.2 - Album bug fix plus async + await
Version 1.2 - Now supports delete method.
Version 1.1 - No more aws-sdk dependecies.
License
MIT