1.0.29 • Published 11 months ago

@proteinjs/db-file-storage-driver-gcs v1.0.29

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Setup

  1. Create a new storage bucket in Google Cloud Storage
  2. Associate a Service Account with the bucket
  3. Create a new access key for the Service Account, or use a previously downloaded key if you have one, in Google Cloud Service Accounts. This is found in the IAM & Admin section of Google Cloud. Creating a new key will automatically download the file.
  4. Once the key is downloaded, navigate to the file location in your terminal to encode it. cat your-key-abcde123456.json | base64 Keep the string that is returned to save as an environment variable on your machine.
  5. Edit your environment variables. For example:
  • nano ~/.zshrc
  • Add this line export GCP_GCS_SA_KEY="paste the long string, that you copied from the previous step, here"
  1. Reload your current terminal session to apply the environment variable changes source ~/.zshrc
  2. Implement a FileStorageDriverFactory to provide your GCS config as the default driver for the FileStorage api. Alternatively, you can pass the driver into FileStorage directly without the following convenience factory.
import { DefaultFileStorageDriverFactory, FileStorageDriver } from '@proteinjs/db-file';
import { GoogleCloudStorageDriver } from '@proteinjs/db-file-storage-driver-gcs';

export class FileStorageDriverFactory implements DefaultFileStorageDriverFactory {
  getDriver(): FileStorageDriver {
    const encodedCredentials = process.env.GCP_GCS_SA_KEY;
    if (!encodedCredentials) {
      throw new Error(
        'Unable to instantiate GoogleCloudStorageDriver. The GCP_GCS_SA_KEY environment variable is not set.'
      );
    }

    const credentials = JSON.parse(Buffer.from(encodedCredentials, 'base64').toString('utf-8'));
    return new GoogleCloudStorageDriver({
      projectId: 'your-project-id',
      bucketName: 'your-bucket-name',
      storageOptions: {
        credentials,
      },
    });
  }
}
1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago