This apparently is also an issue in other plugins. Using environment variables as part of the plugin configuration is not possible.
Original post
Following will return undefined/media as prefix in API calls, however images will be uploaded to the directory path in S3 using the prefix value from .env. So you will have to manually generate the file URL to inject the env variable (which works for some reason).
export default buildConfig({
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
collections: [Page, Media],
typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'),
},
graphQL: {
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
},
plugins: [
cloudStorage({
collections: {
media: {
adapter, // see docs for the adapter you want to use
disablePayloadAccessControl: true,
prefix: `${process.env.S3_PREFIX}/media`,
// generateFileURL: (args) => `https://s3.${process.env.S3_REGION}.amazonaws.com/${process.env.S3_BUCKET}/${process.env.S3_PREFIX}/media/${args.filename}`,
disableLocalStorage: true,
},
},
}),
],
});
Because it returns undefined/media but the file is actually stored in my-prefix/media, then the media files aren't deleted automatically from the bucket when media items are deleted in cms.
Update
This apparently is also an issue in other plugins. Using environment variables as part of the plugin configuration is not possible.
Original post
Following will return
undefined/media
as prefix in API calls, however images will be uploaded to the directory path in S3 using the prefix value from.env
. So you will have to manually generate the file URL to inject the env variable (which works for some reason).Adapter for reference:
Because it returns
undefined/media
but the file is actually stored inmy-prefix/media
, then the media files aren't deleted automatically from the bucket when media items are deleted in cms.