1.0.29 • Published 8 months ago

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

Weekly downloads
-
License
ISC
Repository
github
Last release
8 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

8 months ago

1.0.28

8 months ago

1.0.27

8 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

10 months ago

1.0.23

10 months ago

1.0.22

10 months ago

1.0.21

10 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago