
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@ritani/strapi-provider-upload-google-cloud-storage
Advanced tools
Google Cloud Storage Provider for Strapi Upload, clone from https://github.com/strapi-community/strapi-provider-upload-google-cloud-storage
Non-Official Google Cloud Storage Provider for Strapi Upload
Install the package from your app root directory
with npm
npm install @strapi-community/strapi-provider-upload-google-cloud-storage --save
or yarn
yarn add @strapi-community/strapi-provider-upload-google-cloud-storage
The bucket should be created with fine grained access control, as the plugin will configure uploaded files with public read access.
If you are deploying to a Google Cloud Platform product that supports Application Default Credentials (such as App Engine, Cloud Run, and Cloud Functions etc.), then you can skip this step.
If you are deploying outside GCP, then follow these steps to set up authentication:
JSON for Key Typestring or JSON, be careful with indentation)You will find below many examples of configurations, for each example :
#bucketName# field and replace Bucket-name by yours previously createbaseUrl is working, but you can replace it by yours (if you use a custom baseUrl)Example with application default credentials (minimal setup)
This works only for deployment to GCP products such as App Engine, Cloud Run, and Cloud Functions etc.
Edit ./config/plugins.js
module.exports = {
upload: {
config: {
provider: '@strapi-community/strapi-provider-upload-google-cloud-storage',
providerOptions: {
bucketName: '#bucketName#',
publicFiles: false,
uniform: false,
basePath: '',
},
},
},
//...
}
Example with credentials for outside GCP account
Edit ./config/plugins.js
module.exports = {
upload: {
config: {
provider: '@strapi-community/strapi-provider-upload-google-cloud-storage',
providerOptions: {
bucketName: '#bucketName#',
publicFiles: true,
uniform: false,
serviceAccount: {}, // replace `{}` with your serviceAccount JSON object
baseUrl: 'https://storage.googleapis.com/{bucket-name}',
basePath: '',
},
},
},
//...
}
If you have different upload provider by environment, you can override plugins.js file by environment :
config/env/development/plugins.jsconfig/env/production/plugins.jsThis file, under config/env/{env}/ will be overriding default configuration present in main folder config.
Example with environment variable
module.exports = ({ env }) => ({
upload: {
config: {
provider: '@strapi-community/strapi-provider-upload-google-cloud-storage',
providerOptions: {
serviceAccount: env.json('GCS_SERVICE_ACCOUNT'),
bucketName: env('GCS_BUCKET_NAME'),
basePath: env('GCS_BASE_PATH'),
baseUrl: env('GCS_BASE_URL'),
publicFiles: env('GCS_PUBLIC_FILES'),
uniform: env('GCS_UNIFORM'),
},
},
},
//...
});
Environment variable can be changed has your way.
strapi::security middlewares to avoid CSP blocked urlEdit ./config/middlewares.js
img-src and media-src add your own CDN url, by default it's storage.googleapis.com but you need to add your own CDN urlmodule.exports = [
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'],
'media-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::favicon',
'strapi::public',
];
serviceAccount :JSON data provide by Google Account (explained before). If you are deploying to a GCP product that supports Application Default credentials, you can leave this omitted, and authentication will work automatically.
Can be set as a String, JSON Object, or omitted.
bucketName :The name of the bucket on Google Cloud Storage.
You can find more information on Google Cloud documentation.
baseUrl :Define your base Url, first is default value :
basePath :Define base path to save each media document.
publicFiles:Boolean to define a public attribute to file when it upload to storage.
trueuniform:Boolean to define uniform access, when uniform bucket-level access is enabled.
falsecacheMaxAge:Number to set the cache-control header for uploaded files.
3600gzip:Value to define if files are uploaded and stored with gzip compression.
true, false, autoautometadata:Function that is executed to compute the metadata for a file when it is uploaded.
When no function is provided, the following metadata is used:
{
contentDisposition: `inline; filename="${file.name}"`,
cacheControl: `public, max-age=${config.cacheMaxAge || 3600}`,
}
undefinedExample:
metadata: (file) => ({
cacheControl: `public, max-age=${60 * 60 * 24 * 7}`, // One week
contentLanguage: 'en-US',
contentDisposition: `attachment; filename="${file.name}"`,
}),
The available properties can be found in the Cloud Storage JSON API documentation.
generateUploadFileName:Function that is executed to generate the name of the uploaded file. This method can give more control over the file name and can for example be used to include a custom hashing function or dynamic path.
When no function is provided, the default algorithm is used.
undefinedExample:
generateUploadFileName: (file) => {
const hash = ...; // Some hashing function, for example MD-5
const extension = file.ext.toLowerCase().substring(1);
return `${extension}/${slugify(path.parse(file.name).name)}-${hash}.${extension}`;
},
Error uploading file to Google Cloud Storage: Cannot insert legacy ACL for an object when uniform bucket-level access is enabled
When this error occurs, you need to set uniform variable to true.
Error: Error parsing data "Service Account JSON", please be sure to copy/paste the full JSON file
When this error occurs, it's probably because you have missed something with the service account json configuration.
Follow this step :
ServiceAccount json fileServiceAccount in plugins.js config file in JSONDue to release of Strapi v4, you need to migrate your databases files informations. Follow our migration guide.
You can also used official support platform of Strapi, and search @Lith (maintainer)
See the MIT License file for licensing information.
FAQs
Google Cloud Storage Provider for Strapi Upload, clone from https://github.com/strapi-community/strapi-provider-upload-google-cloud-storage
We found that @ritani/strapi-provider-upload-google-cloud-storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.