Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ntegral/nestjs-s3

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ntegral/nestjs-s3

Provides an injectable s3 client to provide s3 storage access from nestjs modules

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
332
decreased by-9.29%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Codecov Coverage ISC license

@ntegral/nestjs-s3

Provides an injectable S3 client to provide s3 storage access from nestjs modules

Table Of Contents

About

@ntegral/nestjs-s3 implements a module, S3Module, which when imported into your nestjs project provides an S3 client to any class that injects it. This lets AWS S3 be worked into your dependency injection workflow without having to do any extra work outside of the initial setup.

Installation

npm install --save @ntegral/nestjs-s3 aws-sdk

Getting Started

The simplest way to use @ntegral/nestjs-s3 is to use S3Module.forRoot

import { Module } from '@nestjs-common';
import { S3Module } from '@ntegral/nestjs-s3';

@Module({
  imports: [
    S3Module.forRoot({
      accessKeyId: 'aws_access_key_id',
      secretAccessKey: 'aws_secret_access_key',
      region?: 'aws_region_id',
      sessionToken?: 'aws_session_token', | null, 
      apiVersion?: 's3_api_version' //based on s3 api version //
    }),
  ],
})
export class AppModule {}

The async way @ntegral/nestjs-s3 is to use S3Module.forRootAsync

import { Module } from '@nestjs-common';
import { S3Module } from '@ntegral/nestjs-s3';
import { ConfigModule } from '@ntegral/nestjs-config';
import { ConfigService } from '@ntegral/nestjs-config';

@Module({
  imports: [
    S3Module.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (cfg:ConfigService) => ({
        accessKeyId: cfg.get('ACCESS_KEY_ID'),
        secretAccessKey: 'AWS_SECRET_ACCESS_KEY'
      }),
      inject: [ConfigService],
    })
  ]
})

export class AppModule {}

You can then inject the S3 client into any of your injectables by using a custom decorator

import { Injectable } from '@nestjs/common';
import { InjectS3 } from '@ntegral/nestjs-s3';
import * as S3 from 'aws-sdk/clients/s3';

@Injectable()
export class AppService {
  public constructor(@InjectS3() private readonly client: S3) { }

  upload(pdf) {
        const params = {
        ACL: 'public-read',
        Body: pdf,
        Bucket: process.env.BUCKET,
        Key: uuidv4(),
        ContentEncoding: 'base64',
        ContentType: `application/pdf`
    };
    try {
        const { Location, Key } = await this.client.upload(params).promise();
        return Location;
    } catch (error) {
        console.log('ERROR S3 FILE UPLOAD => ', error);
    }
  }
}

Contributing

I would greatly appreciate any contributions to make this project better. Please make sure to follow the below guidelines before getting your hands dirty.

  1. Fork the repository
  2. Create your branch (git checkout -b my-branch)
  3. Commit any changes to your branch
  4. Push your changes to your remote branch
  5. Open a pull request

License

Distributed under the ISC License. See LICENSE for more information.

Acknowledgements

Copyright © 2020 Ntegral Inc.

Keywords

FAQs

Package last updated on 19 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc