Skip to content

plugin-cloud-storage: 403 forbidden when uploading a file #4841

@orasik

Description

@orasik

Hi,
I'm receiving a 403 error when uploading a file to media. Sometimes I see the following error in logs:

NoSuchKey: The specified key does not exist. 

But other times, nothing is showing in logs. I only see 403 error in the browser console.

Context:

The pod deployment is connected to S3 via IAM policy. I have validated the connectivity by CLI and writing a small script to upload a file to S3 from the pod. I am not using access keys or access secrets.

Config

export default buildConfig({
  collections: [Users, Connections, Media],
  typescript: {
    outputFile: path.resolve(__dirname, "payload-types.ts"),
  },
  debug: true,
  upload: {
    useTempFiles: true,
  },
  plugins: [
    cloudStorage({
      collections: {
        'media': {
          adapter: s3Adapter({
            config: {
              region: process.env.S3_REGION,
            },
            bucket: process.env.S3_BUCKET,
          }),
        },
        'connections': {
          adapter: s3Adapter({
            config: {
              region: process.env.S3_REGION,
            },
            bucket: process.env.S3_BUCKET,
          }), // see docs for the adapter you want to use
        },
      },
    }),
  ],
});

Media file

export const Media: CollectionConfig = {
  slug: "media",
  access: {
    read: () => true,
    create: () => true,
    update: () => true,
    delete: () => true,
  },
  admin: {
    useAsTitle: "name",
  },
  upload: {
    staticURL: "/media",
    staticDir: "media",
    disableLocalStorage: true,
    imageSizes: [
      {
        name: "thumbnail",
        width: 400,
        height: 300,
        position: "centre",
      },
      {
        name: "card",
        width: 768,
        height: 1024,
        position: "centre",
      },
      {
        name: "tablet",
        width: 1024,
        height: undefined,
        position: "centre",
      },
    ],
    adminThumbnail: "thumbnail",
    mimeTypes: ["image/*"],
  },
  fields: [
    {
      name: "alt",
      type: "text",
    },
  ],
};

Console URL that is showing 403

'/api/media?locale=en&fallback-locale=null'

Browser

I tried Chrome and Firefox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions