npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-s3-typescript

v4.0.6

Published

A npm package to upload your files into AWS S3 Bucket directly using react

Downloads

242

Readme

react-s3-typescript

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.

Read more about AWS S3 bucket: https://docs.aws.amazon.com/s3/index.html

Features

  • Upload files to S3 bucket and retrieve the public url
  • Delete files from S3 bucket
  • Upload large or big file with progress
  • Aws Javascript SDK Version 3 Integrated!
  • No unnecessary Dependencies
  • Small in Size

Installing

Using npm

$ npm install react-s3-typescript

Example

Upload a file to AWS S3 Bucket

You can define a default directory for uploads using the s3Config object

    /* s3Config.ts */
    /* Configure Aws S3 */

    export const s3Config = {
        bucketName:  'bucket-name',
        dirName: 'directory-name',      /* Optional */
        region: 'ap-south-1',
        accessKeyId:'ABCD12EFGH3IJ4KLMNO8',
        secretAccessKey: 'a12bCde3f4+5GhIjKLm6nOpqr7stuVwxy8ZA9bC9',
        s3Url: 'https:/your-aws-s3-bucket-url/'     /* Optional */
    }

    /* End of s3Config.ts */
    /* AWS S3 Client */
    /* uploadFile.ts */
    import { ReactS3Client } from 'react-s3-typescript';
    import { s3Config } from './s3Config.ts';

    const uploadFile = async () => {
        const s3 = new ReactS3Client(s3Config);

        /* You can use the default directory defined in s3Config object
        * Or you can a define custom directory to upload when calling the
        * constructor using js/ts object destructuring.
        * 
        * const s3 = new ReactS3Client({
        *      ...s3Config,
        *      dirName: 'custom-directory'
        * });
        * 
        */

        const filename = 'filename-to-be-uploaded';     /* Optional */

        /* If you do not specify a file name, file will be uploaded using uuid generated 
        * by short-UUID (https://www.npmjs.com/package/short-uuid)
        */
        const res = await s3.uploadFile(file, filename);

        console.log(res);

    /* End of uploadFile.ts */

Upload big or large file with progress status

    /* AWS S3 Client */
    /* uploadFile.ts */
    import { ReactS3Client } from 'react-s3-typescript';
    import { s3Config } from './s3Config.ts';

    const uploadFile = async () => {
        const s3 = new ReactS3Client(s3Config);

        /* You can use the default directory defined in s3Config object
        * Or you can a define custom directory to upload when calling the
        * constructor using js/ts object destructuring.
        * 
        * const s3 = new ReactS3Client({
        *      ...s3Config,
        *      dirName: 'custom-directory'
        * });
        * 
        */

        const filename = 'filename-to-be-uploaded';     /* Optional */

        /* If you do not specify a file name, file will be uploaded using uuid generated 
        * by short-UUID (https://www.npmjs.com/package/short-uuid)
        */
        const res = await s3.uploadWithProgress(
            file,
            //Progress Callback
            (progress, details) => {
                //Progress in number (0.00 to 1.00)
                console.log("Progress in number", progress);
                console.log("Progress Details", details);
            },
            filename
        );

        //Final Result
        console.log(res);

    /* End of uploadFile.ts */

Delete a file from AWS S3 Bucket

    /* AWS S3 Client */
    /* deleteFile.ts */
    import { ReactS3Client } from 'react-aws-s3-typescript';
    import { s3Config } from './s3Config.ts';

    const deleteFile = async () => {
        const s3 = new ReactS3Client(s3Config);
        const filepath = 'directory-name/filename-to-be-deleted';

        const data = await s3.deleteFile(filepath);

        console.log(data);
    }

    /* End of deleteFile.ts */

Important : Add public-read Canned ACL to the bucket to grant the public read access for files.

Read more: https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl

S3 Config

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.

Stay in touch

License

Released under MIT license.

Back to top