1.0.29 • Published 11 months ago
@proteinjs/db-file-storage-driver-gcs v1.0.29
Setup
- Create a new storage bucket in Google Cloud Storage
- Associate a Service Account with the bucket
- 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.
- 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. - 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"
- Reload your current terminal session to apply the environment variable changes
source ~/.zshrc
- Implement a
FileStorageDriverFactory
to provide your GCS config as the default driver for theFileStorage
api. Alternatively, you can pass the driver intoFileStorage
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