Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@ntegral/nestjs-s3
Advanced tools
Provides an injectable s3 client to provide s3 storage access from nestjs modules
Provides an injectable S3 client to provide s3 storage access from nestjs modules
@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.
npm install --save @ntegral/nestjs-s3 aws-sdk
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);
}
}
}
I would greatly appreciate any contributions to make this project better. Please make sure to follow the below guidelines before getting your hands dirty.
git checkout -b my-branch
)Distributed under the ISC License. See LICENSE
for more information.
Copyright © 2020 Ntegral Inc.
FAQs
Provides an injectable s3 client to provide s3 storage access from nestjs modules
We found that @ntegral/nestjs-s3 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.