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.

Amazon S3 for images

default discord avatar
liorix2 years ago
15

Hi, I've configured S3 to be our image cloud storage. I'm getting this error message when I try to upload an image:



[12:45:18] ERROR (NoSuchKey): The specified key does not exist.


NoSuchKey: The specified key does not exist.


at deserializeAws_restXmlNoSuchKeyResponse...



This is my setup, am I missing something? We were able to make it work a while back but now as we're preparing to go live with our new CMS and set the production env, we again unable to make it work.



env:



"@payloadcms/plugin-cloud-storage": "^1.0.14",


"payload": "1.5.9",


"@aws-sdk/client-s3": "^3.272.0",


"@aws-sdk/lib-storage": "^3.272.0",




payload config code:



let cloudStorageAdapter: Adapter;



cloudStorageAdapter = s3Adapter({


config: {


forcePathStyle: false,


region: process.env.S3_REGION,


credentials: {


accessKeyId: process.env.S3_ACCESS_KEY_ID,


secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,


},


},


bucket: process.env.S3_BUCKET,


});




...



plugins: [


// Pass the plugin to Payload


cloudStorage({


collections: {


media: {


adapter: cloudStorageAdapter,


},


},


}),



....

  • discord user avatar
    denolfe
    2 years ago

    Have you tried changing

    forcePathStyle

    to true?



    You might also need to set

    config.endpoint

    to

    https://s3.amazonaws.com

    as seen here:

    https://github.com/payloadcms/plugin-cloud-storage/blob/master/dev/src/payload.config.ts#LL31C41-L31C41
  • default discord avatar
    liorix2 years ago

    Hi @denolfe .. I tried, this is my updated config:



    cloudStorageAdapter = s3Adapter({


    config: {


    endpoint: '

    https://s3.amazonaws.com

    ',


    forcePathStyle: true,


    region: process.env.S3_REGION,


    credentials: {


    accessKeyId: process.env.S3_ACCESS_KEY_ID,


    secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,


    },


    },


    bucket: process.env.S3_BUCKET,


    });



    I'm now getting the following error:



    (PermanentRedirect): The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.



    the endpoint config has no trailing "/", for some reason discord add it when I send the message

  • discord user avatar
    denolfe
    2 years ago

    Is your S3_BUCKET value configured as just the name? It

    shouldn't

    include

    s3-<region>.amazonaws.com

    in it.

  • default discord avatar
    liorix2 years ago

    Yes, it includes just the name



    @denolfe I still couldn't find a solution. I upgraded to the latest version of payload as well but no luck with the s3 storage

  • discord user avatar
    denolfe
    2 years ago

    I'd do some research on that specific error. Could be something on the AWS side of things. Have you tried using the AWS CLI to do a simple read/write to see if you get any errors?

  • discord user avatar
    dribbens
    2 years ago

    @liorix Does it work if you remove the

    region

    setting?


    I've had this mess me up before.

  • default discord avatar
    liorix2 years ago

    @dribbens eventually it looks like it's working. on my machine I get this error by my cto and test environment is working as expected.



    btw, does the forcePathStyle parameter still working or I should use the generateFileURL parameter to build the s3 full path url?

  • discord user avatar
    dribbens
    2 years ago

    @liorix, Is this still giving you trouble?


    forcePathStyle

    should work, I don't know of any issues surrounding it.

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.