Parse Server GCS Adapter
The Parse Server Google Cloud Storage Adapter.
Installation
npm install --save @parse/gcs-files-adapter
Usage with Parse Server
Config File
{
appId: 'my_app_id',
masterKey: 'my_master_key',
filesAdapter: {
module: '@parse/gcs-files-adapter',
options: {
projectId: 'projectId',
keyFilename: '/path/to/keyfile',
bucket: 'my_bucket',
bucketPrefix: '',
directAccess: false
}
}
}
Environment Variables
Set your environment variables:
GCP_PROJECT_ID=projectId
GCP_KEYFILE_PATH=/path/to/keyfile
GCS_BUCKET=bucketName
And update your config / options
{
appId: 'my_app_id',
masterKey: 'my_master_key',
filesAdapter: '@parse/gcs-files-adapter'
}
Alternatively, you can use
GCLOUD_PROJECT
and GOOGLE_APPLICATION_CREDENTIALS
environment variables.
Instance Parameters
var GCSAdapter = require('@parse/gcs-files-adapter');
var gcsAdapter = new GCSAdapter(
'project',
'keyFilePath',
'bucket' , {
bucketPrefix: '',
directAccess: false
}
);
var api = new ParseServer({
appId: 'my_app',
masterKey: 'master_key',
filesAdapter: gcsAdapter
})
or with an options hash
var GCSAdapter = require('@parse/gcs-files-adapter');
var gcsOptions = {
projectId: 'projectId',
keyFilename: '/path/to/keyfile',
bucket: 'my_bucket',
bucketPrefix: '',
directAccess: false
}
var gcsAdapter = new GCSAdapter(gcsOptions);
var api = new ParseServer({
appId: 'my_app',
masterKey: 'master_key',
filesAdapter: gcsAdapter
});
Options
directAccess
: if set to true
, uploaded files will be set as public and files will be served directly by Google Cloud Storage. Default is false
and files are proxied by Parse Server.
Obtaining Credentials File
See the Google Cloud documentation for how to generate a key file with credentials.