0.0.9 • Published 2 years ago

@roit/roit-storage v0.0.9

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

ROIT Storage

Usage for Google Cloud Storage

In the env.yaml file add the googleStorageCredential{} attribute, with the number of folders inside the {}:

dev:
    googleStorageCredential{5}: my-credential.json

Inject in your desired class:

import { GoogleCloudHandler } from '@roit/roit-storage'

constructor( 
    private readonly googleCloudHandler: GoogleCloudHandler
) {}

To use the retrieveFromStorage method:

const filePath = 'path/from/my/file'
const bucketName = 'my-files-bucket'

const url = await this.googleCloudHandler.retrieveFromStorage(filePath, bucketName)
console.log(url) // outputs https://storage.googleapis.com/...

To use the getSignedUrl method:

const filePath = 'path/from/my/file'
const bucketName = 'my-files-bucket'

const url = await this.googleCloudHandler.getSignedUrl(filePath, bucketName)
console.log(url) 

The getSignedUrl method returns a URL from Google that you need to perform a HTTP POST with the binary encoded file you want to upload, here is a example in Insomnia:

insomnia-example

Nestjs Usage

In Nestjs, don't forget to add the GoogleCloudHandler on the AppModule as a provider:

@Module({
  imports: [],
  controllers: [],
  providers: [
    GoogleCloudHandler
  ],
})
export class AppModule { }
0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago