{"_id":"@devx-strapi/strapi-provider-upload-google-cloud-storage","name":"@devx-strapi/strapi-provider-upload-google-cloud-storage","dist-tags":{"latest":"4.10.6"},"versions":{"4.10.6":{"name":"@devx-strapi/strapi-provider-upload-google-cloud-storage","version":"4.10.6","description":"(Non-official) Google Cloud Storage Provider for Strapi Upload","keywords":["strapi","upload","provider","google","storage","gcp"],"homepage":"https://github.com/devx-agency/strapi-provider-upload-google-cloud-storage#readme","bugs":{"url":"https://github.com/devx-agency/strapi-provider-upload-google-cloud-storage/issues"},"license":"MIT","author":{"name":"Vanessa Pasque","email":"lith@amykron.com"},"maintainers":[{"name":"devx","email":"office@devx.agency"}],"main":"./lib","directories":{"lib":"./lib"},"scripts":{"test":"mocha","lint":"eslint .","coverage":"nyc npm run test"},"repository":{"type":"git","url":"git+ssh://git@github.com/devx-agency/strapi-provider-upload-google-cloud-storage.git"},"dependencies":{"@google-cloud/storage":"^6.10.0","slugify":"^1.6.6"},"devDependencies":{"codecov":"^3.8.3","eslint":"^8.40.0","eslint-config-prettier":"^8.8.0","eslint-plugin-import":"^2.27.5","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^4.2.1","mocha":"^10.2.0","mock-require":"^3.0.3","nyc":"^15.1.0","prettier":"^2.8.8"},"engines":{"node":">=18.0.0 <=20.x.x","npm":">=8"},"strapi":{"isProvider":true},"publishConfig":{"access":"public"},"_id":"@devx-strapi/strapi-provider-upload-google-cloud-storage@4.10.6","gitHead":"8c4799a66c104a01b398b022a6663f96405dc959","_nodeVersion":"20.18.2","_npmVersion":"10.8.2","dist":{"integrity":"sha512-8X8/iLMUx5bJBlA7qR1rEpVS30+8+smFWZmsfzf9hFCqOVqBTAVqlIK16982WQIh1qutoFCKvs3sQ+wyejitEw==","shasum":"fa1455a621c13caa52f8b0493bb6592543e0bf61","tarball":"https://registry.npmjs.org/@devx-strapi/strapi-provider-upload-google-cloud-storage/-/strapi-provider-upload-google-cloud-storage-4.10.6.tgz","fileCount":19,"unpackedSize":39119,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDPBba4aKRUoCQv/28Ro3XT/Erg4BTemgBfSSamtrBrmAiEAoIDSyjLhkBlqnVYsO0TTSMoqNXGQICFRvMdoILwY18A="}]},"_npmUser":{"name":"devx","email":"office@devx.agency"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/strapi-provider-upload-google-cloud-storage_4.10.6_1739791495177_0.45968886230047423"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-17T11:24:55.116Z","4.10.6":"2025-02-17T11:24:55.431Z","modified":"2025-02-17T11:24:55.715Z"},"maintainers":[{"name":"devx","email":"office@devx.agency"}],"description":"(Non-official) Google Cloud Storage Provider for Strapi Upload","homepage":"https://github.com/devx-agency/strapi-provider-upload-google-cloud-storage#readme","keywords":["strapi","upload","provider","google","storage","gcp"],"repository":{"type":"git","url":"git+ssh://git@github.com/devx-agency/strapi-provider-upload-google-cloud-storage.git"},"author":{"name":"Vanessa Pasque","email":"lith@amykron.com"},"bugs":{"url":"https://github.com/devx-agency/strapi-provider-upload-google-cloud-storage/issues"},"license":"MIT","readme":"# strapi-provider-upload-google-cloud-storage\n\n[![npm version](https://img.shields.io/npm/v/@devx-strapi/strapi-provider-upload-google-cloud-storage.svg)](https://www.npmjs.org/package/@devx-strapi/strapi-provider-upload-google-cloud-storage)\n[![npm downloads](https://img.shields.io/npm/dm/@devx-strapi/strapi-provider-upload-google-cloud-storage.svg)](https://www.npmjs.org/package/@devx-strapi/strapi-provider-upload-google-cloud-storage)\n[![coverage](https://codecov.io/gh/strapi-community/strapi-provider-upload-google-cloud-storage/branch/master/graph/badge.svg?token=p4KW9ytA6u)](https://codecov.io/gh/strapi-community/strapi-provider-upload-google-cloud-storage)\n\n**Non-Official** Google Cloud Storage Provider for Strapi Upload\n\n## Installation\n\nInstall the package from your app root directory\n\nwith `npm`\n```\nnpm install @devx-strapi/strapi-provider-upload-google-cloud-storage --save\n```\n\nor `yarn`\n```\nyarn add @devx-strapi/strapi-provider-upload-google-cloud-storage\n```\n\n## <a name=\"create-bucket\"></a> Create your Bucket on Google Cloud Storage\n\nThe bucket should be created with **fine grained** access control, as the plugin will configure uploaded files with public read access.\n\n### How to create a bucket ?\n- https://cloud.google.com/storage/docs/creating-buckets\n\n### Where my bucket can be located ?\n- https://cloud.google.com/storage/docs/locations\n\n## <a name=\"setup-auth\"></a> Setting up Google authentication\n\nIf you are deploying to a Google Cloud Platform product that supports [Application Default Credentials](https://cloud.google.com/docs/authentication/production#finding_credentials_automatically) (such as App Engine, Cloud Run, and Cloud Functions etc.), then you can skip this step. \n\nIf you are deploying outside GCP, then follow these steps to set up authentication:\n\n1. In the GCP Console, go to the **Create service account key** page.\n    - **[Go to the create service account key page](https://console.cloud.google.com/apis/credentials/serviceaccountkey)**\n2. From the **Service account** list, select **New service account**.\n3. In the **Service account name** field, enter a name.\n4. From the **Role** list, select **Cloud Storage > Storage Admin**.\n5. Select `JSON` for **Key Type**\n6. Click **Create**. A JSON file that contains your key downloads to your computer.\n7. Copy the full content of the downloaded JSON file\n8. Open the Strapi configuration file \n9. Paste it into the \"Service Account JSON\" field (as `string` or `JSON`, be careful with indentation)\n\n## Setting up the configuration file\n\nYou will find below many examples of configurations, for each example :\n\n1. If you are deploying outside GCP, then follow the steps above [Setting up Google authentication](#setup-auth)\n2. Set the `#bucketName#` field and replace `Bucket-name` by yours [previously create](#create-bucket)\n3. Default `baseUrl` is working, but you can replace it by yours (if you use a custom baseUrl)\n4. Save the configuration file\n5. Enjoy !\n\n**Example with application default credentials (minimal setup)**\n\nThis works only for deployment to GCP products such as App Engine, Cloud Run, and Cloud Functions etc.\n\nEdit `./config/plugins.js`\n\n```js\nmodule.exports = {\n    upload: {\n      config: {\n        provider: '@devx-strapi/strapi-provider-upload-google-cloud-storage',\n        providerOptions: {\n            bucketName: '#bucketName#',\n            publicFiles: false,\n            uniform: false,\n            basePath: '',\n        },\n      },\n    },\n    //...\n}\n```\n\nIf 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.\n\nYou can set the expiry time of the signed URL by setting the `expires` option in the `providerOptions` object. See more in [expires](#expires).\n\n**Example with credentials for outside GCP account**\n\nEdit `./config/plugins.js`\n\n```js\nmodule.exports = {\n    upload: {\n      config: {\n        provider: '@devx-strapi/strapi-provider-upload-google-cloud-storage',\n        providerOptions: {\n            bucketName: '#bucketName#',\n            publicFiles: true,\n            uniform: false,\n            serviceAccount: {}, // replace `{}` with your serviceAccount JSON object\n            baseUrl: 'https://storage.googleapis.com/{bucket-name}',\n            basePath: '',\n        },\n      },\n    },\n    //...\n}\n```\n\nIf you have different upload provider by environment, you can override `plugins.js` file by environment : \n- `config/env/development/plugins.js`\n- `config/env/production/plugins.js`\n\nThis file, under `config/env/{env}/` will be overriding default configuration present in main folder `config`.\n\n**Example with environment variable**\n\n```js\nmodule.exports = ({ env }) => ({\n    upload: {\n      config: {\n        provider: '@devx-strapi/strapi-provider-upload-google-cloud-storage',\n        providerOptions: {\n          serviceAccount: env.json('GCS_SERVICE_ACCOUNT'),\n          bucketName: env('GCS_BUCKET_NAME'),\n          basePath: env('GCS_BASE_PATH'),\n          baseUrl: env('GCS_BASE_URL'),\n          publicFiles: env('GCS_PUBLIC_FILES'),\n          uniform: env('GCS_UNIFORM'),\n        },\n      },\n    },\n    //...\n});\n```\n\nEnvironment variable can be changed has your way.\n\n## Setting up `strapi::security` middlewares to avoid CSP blocked url\n\nEdit `./config/middlewares.js`\n- In the field `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 url\n\n```js\nmodule.exports = [\n  'strapi::errors',\n  {\n    name: 'strapi::security',\n    config: {\n      contentSecurityPolicy: {\n        useDefaults: true,\n        directives: {\n          'connect-src': [\"'self'\", 'https:'],\n          'img-src': [\"'self'\", 'data:', 'blob:', 'storage.googleapis.com'],\n          'media-src': [\"'self'\", 'data:', 'blob:', 'storage.googleapis.com'],\n          upgradeInsecureRequests: null,\n        },\n      },\n    },\n  },\n  'strapi::cors',\n  'strapi::poweredBy',\n  'strapi::logger',\n  'strapi::query',\n  'strapi::body',\n  'strapi::favicon',\n  'strapi::public',\n];\n```\n\n## How to configure variable ?\n\n#### `serviceAccount` :\n\nJSON 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.\n\nCan be set as a String, JSON Object, or omitted.\n\n#### `bucketName` :\n\nThe name of the bucket on Google Cloud Storage.\n- Required\n\nYou can find more information on Google Cloud documentation.\n\n#### `baseUrl` :\n\nDefine your base Url, first is default value :\n- https://storage.googleapis.com/{bucket-name}\n- https://{bucket-name}\n- http://{bucket-name}\n\n#### `basePath` :\n\nDefine base path to save each media document.\n- Optional\n\n#### `publicFiles`:\n\nBoolean to define a public attribute to file when upload file to storage.\n- Default value : `true`\n- Optional\n\n#### `uniform`:\n\nBoolean to define `uniform` access, when uniform bucket-level access is enabled.\n- Default value : `false`\n- Optional\n\n#### `skipCheckBucket`:\n\nBoolean to define `skipCheckBucket`, when skipCheckBucket is enabled, we skip to check if the bucket exist. It's useful for private bucket.\n- Default value : `false`\n- Optional\n\n#### `cacheMaxAge`:\n\nNumber to set the cache-control header for uploaded files.\n- Default value : `3600`\n- Optional\n\n#### `gzip`:\n\nValue to define if files are uploaded and stored with gzip compression.\n- Possible values: `true`, `false`, `auto`\n- Default value : `auto`\n- Optional\n\n#### `expires`:\n\nValue to define expiration time for signed URLS. Files are signed when `publicFiles` is set to `false`.\n\n- Possible values: `Date`, `number`, `string`\n- Default value : `900000` (15 minutes)\n- Max value : `604800000` (7 days)\n- Optional\n\n### `metadata`:\n\nFunction that is executed to compute the metadata for a file when it is uploaded. \n\nWhen no function is provided, the following metadata is used:\n\n```js\n{\n  contentDisposition: `inline; filename=\"${file.name}\"`,\n  cacheControl: `public, max-age=${config.cacheMaxAge || 3600}`,\n}\n```\n\n- Default value: `undefined`\n- Optional\n\nExample:\n\n```js\n  metadata: (file) => ({\n    cacheControl: `public, max-age=${60 * 60 * 24 * 7}`, // One week\n    contentLanguage: 'en-US',\n    contentDisposition: `attachment; filename=\"${file.name}\"`,\n  }),\n```\n\nThe available properties can be found in the [Cloud Storage JSON API documentation](https://cloud.google.com/storage/docs/json_api/v1/objects/insert#request_properties_JSON).\n\n### `generateUploadFileName`:\n\nFunction 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.\n\nWhen no function is provided, the [default algorithm](lib/provider.js) is used.\n\n- Default value: `undefined`\n- Optional\n\nExample:\n\n```js\n  generateUploadFileName: async (file) => {\n    const hash = await ...; // Some hashing function, for example MD-5\n    const extension = file.ext.toLowerCase().substring(1);\n    return `${extension}/${slugify(path.parse(file.name).name)}-${hash}.${extension}`;\n  },\n```\n\n\n## FAQ\n\n### Common errors\n\n#### Uniform access \n\n`Error uploading file to Google Cloud Storage: Cannot insert legacy ACL for an object when uniform bucket-level access is enabled`\n\nWhen this error occurs, you need to set `uniform` variable to `true`.\n\n#### Service Account JSON\n\n`Error: Error parsing data \"Service Account JSON\", please be sure to copy/paste the full JSON file`\n\nWhen this error occurs, it's probably because you have missed something with the service account json configuration.\n\nFollow this step :\n- Open your `ServiceAccount` json file\n- Copy the full content of the file\n- Paste it under the variable `ServiceAccount` in `plugins.js` config file in JSON\n\n## Migration\n\nDue to release of Strapi v4, you need to migrate your databases files informations.\nFollow our [migration guide](./MIGRATION_GUIDE.md).\n\n## Links\n\n- [Strapi website](http://strapi.io/)\n- [Strapi community on Slack](http://slack.strapi.io)\n- [Strapi news on Twitter](https://twitter.com/strapijs)\n\n## Community support\n\n- [GitHub](https://github.com/strapi-community/strapi-provider-upload-google-cloud-storage) (Bug reports, contributions)\n  \nYou can also used official support platform of Strapi, and search `@Lith` (maintainer) \n\n- [Discord](https://discord.strapi.io) (For live discussion with the Community and Strapi team)\n- [Community Forum](https://forum.strapi.io) (Questions and Discussions)\n\n## License\n\nSee the [MIT License](LICENSE) file for licensing information.\n","readmeFilename":"README.md"}