A aliyun OSS SDK for nest.js.
pnpm i @nailyjs.nest.modules/ali-oss
import { Module } from '@nestjs/common';
import { AliOSSModule } from '@nailyjs.nest.modules/ali-oss';
@Module({
imports: [
AliOSSModule.forRoot(/* options */),
],
})
export class AppModule {}
You can also use AliOSSModule.forRootAsync
to provide options asynchronously.
import { Module } from '@nestjs/common';
import { AliOSSModule } from '@nailyjs.nest.modules/ali-oss';
@Module({
imports: [
AliOSSModule.forRootAsync({
useFactory: () => ({/* options */}),
}),
],
})
export class AppModule {}
Then you can use AliOSSService
to upload files.
import { Injectable } from '@nestjs/common';
import { AliOSSService } from '@nailyjs.nest.modules/ali-oss';
@Injectable()
export class AppService {
constructor(private readonly aliOSSService: AliOSSService) {}
}
You can create multiple AliOSS instances with different configurations.
import { Module } from '@nestjs/common';
import { AliOSSModule } from '@nailyjs.nest.modules/ali-oss';
@Module({
imports: [
AliOSSModule.forRoot([
{
provide: 'AliOSSInstanceName1',
/* options */
},
{
provide: 'AliOSSInstanceName2',
/* options */
}
]),
],
})
export class AppModule {}
Then you can use AliOSSService
with a specific name.
import { Injectable, Inject } from '@nestjs/common';
import { AliOSSService } from '@nailyjs.nest.modules/ali-oss';
@Injectable()
export class AppService {
constructor(
@Inject('AliOSSInstanceName1') private readonly aliOSSService1: AliOSSService,
@Inject('AliOSSInstanceName2') private readonly aliOSSService2: AliOSSService,
) {}
}
👤 Naily Zero
MIT