Google Cloud Storage Module for Nest.js Framework
$ yarn add @aginix/nestjs-gcloud-storage
If you have bucket domain name you can config storageBaseUri
.
import { Module } from '@nestjs/common';
import { GCloudStorageModule } from '@aginix/nestjs-gcloud-storage';
@Module({
imports: [
GCloudStorageModule.withConfig({
defaultBucketname: 'bucket.aginix.tech',
storageBaseUri: 'bucket.aginix.tech',
predefinedAcl: 'private' // Default is publicRead
})
],
})
export class AppModule {}
import { Module } from '@nestjs/common';
import { GCloudStorageModule } from '@aginix/nestjs-gcloud-storage';
import { ConfigService } from './config.service';
import { ConfigModule } from './config.module';
@Module({
imports: [
GCloudStorageModule.withConfigAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
defaultBucketname: config.get('GCS_BUCKET_NAME'),
storageBaseUri: config.get('GCS_DOMAIN_NAME'),
}),
imports: [ConfigModule],
})
],
})
export class AppModule {}
Set predefinedAcl
to null
@Module({
imports: [
GCloudStorageModule.withConfig({
predefinedAcl: null
})
],
})
export class AppModule {}
import {
Controller,
Logger,
Post,
UploadedFile,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
GCloudStorageFileInterceptor,
UploadedFileMetadata,
} from '@aginix/nestjs-gcloud-storage';
@Controller()
export class AppController {
@Post('gcs/upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file'),
)
UploadedFilesUsingInterceptor(
@UploadedFile()
file: UploadedFileMetadata,
) {
Logger.log(`Storage URL: ${file.storageUrl}`, 'AppController');
}
}
import {
Controller,
Logger,
Post,
UploadedFile,
UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import {
GCloudStorageFileInterceptor,
UploadedFileMetadata,
} from '@aginix/nestjs-gcloud-storage';
@Controller()
export class AppController {
@Post('gcs/upload')
@UseInterceptors(
GCloudStorageFileInterceptor('file', undefined, { prefix: 'prefix/test' })
)
UploadedFilesUsingInterceptor(
@UploadedFile()
file: UploadedFileMetadata,
) {
Logger.log(`Storage URL: ${file.storageUrl}`, 'AppController');
}
}
@Controller()
export class AppController {
@Post('gcs/secret-file')
@UseInterceptors(
GCloudStorageFileInterceptor('secret-file', undefined, { predefinedAcl: 'private' })
)
UploadedSecretFile(
@UploadedFile()
file: UploadedFileMetadata,
) {
Logger.log(`Storage URL: ${file.storageUrl}`, 'AppController');
}
}