dm-ali-oss
v0.0.3
Published
<p align="center"> <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a> </p>
Downloads
2
Readme
Description
a dynamic module for ali oss inject difference instance
Installation
$ npm install dm-ali-oss
Quick Start
async configuration
Like other factory providers, our factory function can be async and can inject dependencies through inject.
AliOssModule.registerAsync('P1', {
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return {
accessKeyId: configService.get('ALI_OSS_ACCESS_KEY_ID'),
accessKeySecret: configService.get('ALI_OSS_ACCESS_KEY_SECRET'),
bucket: configService.get('ALI_OSS_BUCKET'),
region: configService.get('ALI_OSS_REGION'),
endpoint:configService.get('ALI_OSS_ENDPOINT'),
};
},
}),
then you can inject with the target provider
@Injectable()
export class AppService {
constructor(@Inject('P1') private readonly aliOssService: AliOssService) {}
async getHello(): Promise<string> {
const result = await this.aliOssService.getObject('test/test.txt');
return result.toString();
}
}
current AliOssService support method
- putObject()
- getObject()
- putAcl()
- createBucket()
- getStream()
you can read details by typings
Test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
License
Nest is MIT licensed.