A npm package to upload your files into AWS S3 Bucket directly using ReactJS or NodeJS with aws sdk version 3. It also support upload with progress functionality.
What new in version 4.0.0
I add a new function for upload large or big file with progress bar status. No other changes.
It supports upload process with progress status(Upload Large File).
Aws SDK Version 3
Introduction
A npm package to upload your media and other types of files directly into AWS S3 Bucket using ReactJs or NodeJS with aws sdk version 3. You can upload and and delete the file if needed! It also support upload with progress bar system.
You need to have an AWS account to use AWS S3 Bucket. If you already do not have an account, create an account here.
1/* AWS S3 Client */2/* uploadFile.ts */3import { ReactS3Client } from'react-s3-typescript';
4import { s3Config } from'./s3Config.ts';
56const uploadFile = async () => {
7const s3 = new ReactS3Client(s3Config);
89/* You can use the default directory defined in s3Config object
10 * Or you can a define custom directory to upload when calling the
11 * constructor using js/ts object destructuring.
12 *
13 * const s3 = new ReactS3Client({
14 * ...s3Config,
15 * dirName: 'custom-directory'
16 * });
17 *
18 */1920const filename = 'filename-to-be-uploaded'; /* Optional */2122/* If you do not specify a file name, file will be uploaded using uuid generated
23 * by short-UUID (https://www.npmjs.com/package/short-uuid)
24 */25const res = await s3.uploadFile(file, filename);
2627console.log(res);
2829/* End of uploadFile.ts */
Upload big or large file with progress status
1/* AWS S3 Client */2/* uploadFile.ts */3import { ReactS3Client } from'react-s3-typescript';
4import { s3Config } from'./s3Config.ts';
56const uploadFile = async () => {
7const s3 = new ReactS3Client(s3Config);
89/* You can use the default directory defined in s3Config object
10 * Or you can a define custom directory to upload when calling the
11 * constructor using js/ts object destructuring.
12 *
13 * const s3 = new ReactS3Client({
14 * ...s3Config,
15 * dirName: 'custom-directory'
16 * });
17 *
18 */1920const filename = 'filename-to-be-uploaded'; /* Optional */2122/* If you do not specify a file name, file will be uploaded using uuid generated
23 * by short-UUID (https://www.npmjs.com/package/short-uuid)
24 */25const res = await s3.uploadWithProgress(
26 file,
27//Progress Callback28(progress, details) => {
29//Progress in number (0.00 to 1.00)30console.log("Progress in number", progress);
31console.log("Progress Details", details);
32 },
33 filename
34 );
3536//Final Result37console.log(res);
3839/* End of uploadFile.ts */
These are the available config options for calling the S3 constructor bucketName, region, accessKeyId and secretAccessKey are required. Upload will default to root path, if dirName is not specified.