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

ngx-s3-uploader

v9.0.1

Published

AWS S3 upload directive for Angular 2 and above.

Downloads

85

Readme

ngx-s3-uploader

NPM version MIT License

The library is inspired by AngularJS To S3 Upload App

| Angular version | Integration branch | Library version | |:---------------:|:------------------:|:---------------:| | 5 and below | angular1-5 | ^0.5.0 | | 6 and above | master | ^9.0.0 |

Installation

To install this library, run:

$ npm install ngx-s3-uploader --save

Usage

    import { S3UploaderModule } from 'ngx-s3-uploader';

    @NgModule({
        imports: [
            S3UploaderModule.forRoot({
              region: 'REGION',
              bucket: 'BUCKET_NAME',
              credentials: { accessKeyId: 'ACCESS_KEY_ID', secretAccessKey: 'SECRET_ACCESS_KEY' },
            })
        ],
        ...
    })
    export class AppModule {}

Warning

While it is possible to do so, we recommend you not hard code credentials inside an application or browser script. Hard coding credentials poses a risk of exposing your access key ID and secret access key. See Best Practices in the IAM User Guide.

The recommended way to obtain AWS credentials for your browser scripts is to use the Amazon Cognito Identity credentials. See Identity Pools for instructions to create identity pools.

    import { S3UploaderModule } from 'ngx-s3-uploader';

    @NgModule({
        imports: [
            S3UploaderModule.forRoot({
              region: 'REGION',
              bucket: 'BUCKET_NAME',
              credentials: { identityPoolId: 'IDENTITY_POOL_ID' },
            })
        ],
        ...
    })
    export class AppModule {}

Alternatively you can authenticate with the Web Federated Identity method.

    import { S3UploaderModule } from 'ngx-s3-uploader';

    @NgModule({
        imports: [
            S3UploaderModule.forRoot({
              region: 'REGION',
              bucket: 'BUCKET_NAME',
              credentials: { roleArn: 'ROLE_ARN', roleName: 'ROLE_SESSION_NAME', providerId: 'PROVIDER_ID', token: 'ACCESS_TOKEN' },
            })
        ],
        ...
    })
    export class AppModule {}

As the role session name is adviced to pass the name or identifier that is associated with the user.

Now you can use s3-uploader directive in your Angular application:

  <s3-uploader (success)="uploaded($event)" (error)="uploadError($event)"></s3-uploader>

success will be called in case of success with the response data from the successful upload.

A map containing:

  • Location (String) -- the URL of the uploaded object.
  • ETag (String) -- the ETag of the uploaded object.
  • Bucket (String) -- the bucket to which the object was uploaded.
  • Key (String) -- the key to which the object was uploaded.

error will be called if an error occurred.

If you need direct access to the service you can inject it using Dependency Injection:

    import { S3UploaderService } from 'ngx-s3-uploader';

    @Component({})
    export class AppComponent {
        constructor(private s3UploaderService: S3UploaderService) {}

        private upload(file): void {
            this.s3UploaderService.upload(file, 'ACL_TO_APPLY','KEY<optional>', 'BUCKET_NAME<optional>')
                .subscribe(
                    (data) => {
                        //...
                    },
                    (error) => {
                        //...
                    });
        }
    }

You can also use this service to update logins when using Amazon Cognito Identity:

    import { S3UploaderService } from 'ngx-s3-uploader';

    @Component({})
    export class AppComponent {
        constructor(private s3UploaderService: S3UploaderService) {}

        private facebookLogin(): void {
            FB.login((response) => {
              if (response.authResponse) {
                this.s3UploaderService.authenticate('graph.facebook.com', response.authResponse.accessToken);
              } else {
                console.log('There was a problem logging you in.');
              }
            });
        }
    }

TODO

License

MIT © Jaime