Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

S3 + Crop in Payload 2 not working (plugin-cloud-storage)

default discord avatar
mmthdlast year
5

Hey com,



i actually try to setup a s3 with payload 2.0 with the official plugin-cloud-storage.


The upload & delete actions works fine, but if a want to crop a image before -> it was not applied & when i try to change a image after the upload i get an error:



Browser console:


tsp.bundle.js:1     PATCH https://example.com/api/media/6d326bf0c3029e0bc19f6c02c?depth=0&fallback-locale=null&uploadEdits%5Bcrop%5D%5Bheight%5D=100&uploadEdits%5Bcrop%5D%5Bunit%5D=%25&uploadEdits%5Bcrop%5D%5Bwidth%5D=100&uploadEdits%5Bcrop%5D%5Bx%5D=0&uploadEdits%5Bcrop%5D%5By%5D=0&uploadEdits%5BfocalPoint%5D%5Bx%5D=50&uploadEdits%5BfocalPoint%5D%5By%5D=50 500 (Internal Server Error)


Log:


2023-10-11T15:35:38.475080331Z [15:35:37] ERROR (payload): Error: ENOENT: no such file or directory, open '/app/media/image.png'
2023-10-11T15:35:38.475128331Z at Object.openSync (node:fs:603:3)
2023-10-11T15:35:38.475134851Z at Object.readFileSync (node:fs:471:35)
2023-10-11T15:35:38.475139972Z at getFileByPath (/app/node_modules/payload/dist/uploads/getFileByPath.js:21:34)
2023-10-11T15:35:38.475144932Z at generateFileData (/app/node_modules/payload/dist/uploads/generateFileData.js:46:59)
2023-10-11T15:35:38.475149732Z at updateByID (/app/node_modules/payload/dist/collections/operations/updateByID.js:101:106)
2023-10-11T15:35:38.475154572Z at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-10-11T15:35:38.475159412Z at async updateByIDHandler (/app/node_modules/payload/dist/collections/requestHandlers/updateByID.js:35:21)


i think payload tries to get the file from local filesystem instead of from S3 server, have anyone a solution?

  • default discord avatar
    leonardstrucklast year

    Have you set

    disableLocalStorage: true

    ?

  • discord user avatar
    denolfe
    last year

    Was the working properly at one point or is this the first time you've tried to set it up?


    Can you provide the code you're using to configure the plugin, without any sensitive info?

  • default discord avatar
    mmthdlast year

    This is the first time i try to setup, im new to payload and getting started with 2.0 with the website template which i have upgraded to payload 2.0.4 with npm & actually --force installation. I remove the seed & eject stuff from payload & replaced all imports for the slate editor.



    My config:


    export default buildConfig({
      admin: {
        bundler: webpackBundler(),
        user: Users.slug,
      },
      editor: slateEditor({}),
      db: mongooseAdapter({
        url: process.env.MONGODB_URI,
        migrationDir: './src/payload/migrations',
      }),
      serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
      collections: [Pages, Posts, Projects, Media, Categories, Users, Comments],
      globals: [Settings, Header, Footer],
      typescript: {
        outputFile: path.resolve(__dirname, 'payload-types.ts'),
      },
      graphQL: {
        schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
      },
      cors: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean),
      csrf: [process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(Boolean),
      plugins: [
       cloudStorage({
          collections: {
            media: {
              disableLocalStorage: true,
              adapter: s3Adapter({
                config: {
                  endpoint: process.env.PAYLOAD_S3_ENDPOINT,
                  credentials: {
                    accessKeyId: process.env.PAYLOAD_S3_ACCESS_KEY,
                    secretAccessKey: process.env.PAYLOAD_S3_ACCESS_KEY_SECRET,
                  },
                  region: process.env.PAYLOAD_S3_REGION,
                },
                bucket: process.env.PAYLOAD_S3_BUCKET,
              }),
            },
          },
        }),
        redirects({
          collections: ['pages', 'posts'],
        }),
        nestedDocs({
          collections: ['categories'],
        }),
        seo({
          collections: ['pages', 'posts', 'projects'],
          generateTitle,
          uploadsCollection: 'media',
        }),
      ],
    })


    @aws-sdk/client-s3: ^3.427.0


    @aws-sdk/lib-storage: ^3.427.0


    @payloadcms/plugin-cloud-storage: ^1.0.19



    I have already tried to remove the

    upload

    config from

    media

    collection, or set

    disableLocalStorage

    to

    true

    (in media collection to) but always without effect

  • default discord avatar
    clement6396last year

    Yep, there is an issue with this plugin, the source media is not resized or compressed. Only sizes set in

    imagesSizes

    are working



    The source file: check at size on Payload and on S3







    twice the sized announced, plus webp is just on the title, if you download locally the source image, it's still on jpg

    image.png
    image.png
    image.png
  • discord user avatar
    denolfe
    last year
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.