codebrewlab / nestjs-storage

Nestjs file system / file storage module wrapping flydrive
117 stars 16 forks source link

[ExceptionsHandler] Driver gcs is not supported #5

Closed gcamrit closed 3 years ago

gcamrit commented 3 years ago

I am having issue reading google cloud storage files

app.module.ts

StorageModule.forRootAsync({
  useFactory: () => ({
  default: 'documents',
  disks: {
    documents: {
      driver: DriverType.GCS,
      config: {
        bucket: process.env.GCS_BUCKET,
      },
    },
  },
  })
}),

when i try to use storage service and getSignedUrl i get driver gcs is not supported error

this.storageService.getDisk('documents').getSignedUrl(image.url)
tienne commented 3 years ago

Did you set the keyfilename?

tienne commented 3 years ago

gcs must also be installed with the package below. @slynova/flydrive-gcs see

gcamrit commented 3 years ago

i have already installed @slynova/flydrive-gcs package and provided key file name via env like GOOGLE_APPLICATION_CREDENTIALS=./gcloud.json

gcamrit commented 3 years ago

@tienne Do i need to register gcs driver somewhere ?

tienne commented 3 years ago

Yes As shown in the example below, you must register using the registerDriver method first.

this.storage.registerDriver('s3', AmazonWebServicesS3Storage);

Sorry, I wrote the wrong example

gcamrit commented 3 years ago

where do i put the registration code on app.module.ts ?

tienne commented 3 years ago

I am using the service registered as below.

// image-storage.service.ts
import { Injectable } from '@nestjs/common';
import { AmazonWebServicesS3Storage } from '@slynova/flydrive-s3';
import { StorageService } from '@codebrew/nestjs-storage';

@Injectable()
export class ImageStorageService {
  private readonly disk: AmazonWebServicesS3Storage;

  constructor(private storage: StorageService) {
    if (this.disk === undefined) {
      this.storage.registerDriver('s3', AmazonWebServicesS3Storage);
      this.disk = this.storage.getDisk<AmazonWebServicesS3Storage>();
    }
  }

//...
}
tienne commented 3 years ago

Is this issue resolved by any chance? @gcamrit

gcamrit commented 3 years ago

Yup thanks for the help