<!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # --> ### What? In a similar vein to #11734, #11733, #10327 - this PR returns a 404 in the response when a file is not found while using the `storage-gcs` adapter. Currently a 500 is returned. ### Why? To return the correct error level in the response when a file is not found when using `storage-gcs`. ### How? The GCS nodejs library exposes the `ApiError` as a general error - these changes check that the caught error is an instance of this class and if the provided code is a `404`.
Google Cloud Storage for Payload
This package provides a simple way to use Google Cloud Storage with Payload.
NOTE: This package removes the need to use @payloadcms/plugin-cloud-storage as was needed in Payload 2.x.
Installation
pnpm add @payloadcms/storage-gcs
Usage
- Configure the
collectionsobject to specify which collections should use the Google Cloud Storage adapter. The slug must match one of your existing collection slugs. - When enabled, this package will automatically set
disableLocalStoragetotruefor each collection. - When deploying to Vercel, server uploads are limited with 4.5MB. Set
clientUploadstotrueto do uploads directly on the client. You must allow CORS PUT method for the bucket to your website.
import { gcsStorage } from '@payloadcms/storage-gcs'
import { Media } from './collections/Media'
import { MediaWithPrefix } from './collections/MediaWithPrefix'
export default buildConfig({
collections: [Media, MediaWithPrefix],
plugins: [
gcsStorage({
collections: {
media: true,
'media-with-prefix': {
prefix,
},
},
bucket: process.env.GCS_BUCKET,
options: {
apiEndpoint: process.env.GCS_ENDPOINT,
projectId: process.env.GCS_PROJECT_ID,
},
}),
],
})
Configuration Options
| Option | Description | Default |
|---|---|---|
enabled |
Whether or not to enable the plugin | true |
collections |
Collections to apply the storage to | |
bucket |
The name of the bucket to use | |
options |
Google Cloud Storage client configuration. See Docs | |
acl |
Access control list for files that are uploaded | Private |