1.1.13 • Published 6 months ago
@proteinjs/db-file-storage-driver-gcs v1.1.13
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 | base64Keep 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
FileStorageDriverFactoryto provide your GCS config as the default driver for theFileStorageapi. Alternatively, you can pass the driver intoFileStoragedirectly 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.33
1 year ago
1.0.32
1 year ago
1.0.31
1 year ago
1.0.30
1 year ago
1.0.37
12 months ago
1.0.36
1 year ago
1.0.35
1 year ago
1.0.34
1 year ago
1.1.1
10 months ago
1.1.0
10 months ago
1.0.38
10 months ago
1.1.9
8 months ago
1.1.8
8 months ago
1.1.7
8 months ago
1.1.6
8 months ago
1.1.5
9 months ago
1.1.4
9 months ago
1.1.3
9 months ago
1.1.2
10 months ago
1.1.12
7 months ago
1.1.11
8 months ago
1.1.10
8 months ago
1.1.13
6 months ago
1.0.29
1 year ago
1.0.28
1 year ago
1.0.27
1 year ago
1.0.26
1 year ago
1.0.25
1 year ago
1.0.24
1 year ago
1.0.23
1 year 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