Gathering detailed insights and metrics for @strapi-community/strapi-provider-upload-google-cloud-storage
Gathering detailed insights and metrics for @strapi-community/strapi-provider-upload-google-cloud-storage
Gathering detailed insights and metrics for @strapi-community/strapi-provider-upload-google-cloud-storage
Gathering detailed insights and metrics for @strapi-community/strapi-provider-upload-google-cloud-storage
@ritani/strapi-provider-upload-google-cloud-storage
Google Cloud Storage Provider for Strapi Upload, clone from https://github.com/strapi-community/strapi-provider-upload-google-cloud-storage
@strapi/provider-upload-local
Local provider for strapi upload
@strapi/provider-upload-aws-s3
AWS S3 provider for strapi upload
@strapi/strapi
An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MySQL, MariaDB, PostgreSQL, SQLite
Google Cloud Storage Upload Provider for Strapi
npm install @strapi-community/strapi-provider-upload-google-cloud-storage
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
211 Stars
112 Commits
94 Forks
5 Watching
5 Branches
31 Contributors
Updated on 27 Sept 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5%
698
Compared to previous day
Last week
-0.1%
3,805
Compared to previous week
Last month
1.5%
16,515
Compared to previous month
Last year
-2.5%
216,777
Compared to previous year
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
1module.exports = { 2 upload: { 3 config: { 4 provider: '@strapi-community/strapi-provider-upload-google-cloud-storage', 5 providerOptions: { 6 bucketName: '#bucketName#', 7 publicFiles: false, 8 uniform: false, 9 basePath: '', 10 }, 11 }, 12 }, 13 //... 14}
If you set publicFiles
to false
, the assets will be signed on the Content Manager (not the Content API). Consequently, they will only be visible to users who are authenticated.
You can set the expiry time of the signed URL by setting the expires
option in the providerOptions
object. See more in expires.
Example with credentials for outside GCP account
Edit ./config/plugins.js
1module.exports = { 2 upload: { 3 config: { 4 provider: '@strapi-community/strapi-provider-upload-google-cloud-storage', 5 providerOptions: { 6 bucketName: '#bucketName#', 7 publicFiles: true, 8 uniform: false, 9 serviceAccount: {}, // replace `{}` with your serviceAccount JSON object 10 baseUrl: 'https://storage.googleapis.com/{bucket-name}', 11 basePath: '', 12 }, 13 }, 14 }, 15 //... 16}
If you have different upload provider by environment, you can override plugins.js
file by environment :
config/env/development/plugins.js
config/env/production/plugins.js
This file, under config/env/{env}/
will be overriding default configuration present in main folder config
.
Example with environment variable
1module.exports = ({ env }) => ({ 2 upload: { 3 config: { 4 provider: '@strapi-community/strapi-provider-upload-google-cloud-storage', 5 providerOptions: { 6 serviceAccount: env.json('GCS_SERVICE_ACCOUNT'), 7 bucketName: env('GCS_BUCKET_NAME'), 8 basePath: env('GCS_BASE_PATH'), 9 baseUrl: env('GCS_BASE_URL'), 10 publicFiles: env('GCS_PUBLIC_FILES'), 11 uniform: env('GCS_UNIFORM'), 12 }, 13 }, 14 }, 15 //... 16});
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 url1module.exports = [ 2 'strapi::errors', 3 { 4 name: 'strapi::security', 5 config: { 6 contentSecurityPolicy: { 7 useDefaults: true, 8 directives: { 9 'connect-src': ["'self'", 'https:'], 10 'img-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'], 11 'media-src': ["'self'", 'data:', 'blob:', 'storage.googleapis.com'], 12 upgradeInsecureRequests: null, 13 }, 14 }, 15 }, 16 }, 17 'strapi::cors', 18 'strapi::poweredBy', 19 'strapi::logger', 20 'strapi::query', 21 'strapi::body', 22 'strapi::favicon', 23 'strapi::public', 24];
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 upload file to storage.
true
uniform
:Boolean to define uniform
access, when uniform bucket-level access is enabled.
false
skipCheckBucket
:Boolean to define skipCheckBucket
, when skipCheckBucket is enabled, we skip to check if the bucket exist. It's useful for private bucket.
false
cacheMaxAge
:Number to set the cache-control header for uploaded files.
3600
gzip
:Value to define if files are uploaded and stored with gzip compression.
true
, false
, auto
auto
expires
:Value to define expiration time for signed URLS. Files are signed when publicFiles
is set to false
.
Date
, number
, string
900000
(15 minutes)604800000
(7 days)metadata
: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:
1{ 2 contentDisposition: `inline; filename="${file.name}"`, 3 cacheControl: `public, max-age=${config.cacheMaxAge || 3600}`, 4}
undefined
Example:
1 metadata: (file) => ({ 2 cacheControl: `public, max-age=${60 * 60 * 24 * 7}`, // One week 3 contentLanguage: 'en-US', 4 contentDisposition: `attachment; filename="${file.name}"`, 5 }),
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.
undefined
Example:
1 generateUploadFileName: async (file) => { 2 const hash = await ...; // Some hashing function, for example MD-5 3 const extension = file.ext.toLowerCase().substring(1); 4 return `${extension}/${slugify(path.parse(file.name).name)}-${hash}.${extension}`; 5 },
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.
No vulnerabilities found.
No security vulnerabilities found.