Like what we’re doing? Star us on GitHub!

Amazon S3 for images

liorix
4 weeks 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,


},


},


}),



....

  • denolfe
    Payload Team
    4 weeks 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
  • liorix
    4 weeks 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

  • denolfe
    Payload Team
    4 weeks ago

    Is your S3_BUCKET value configured as just the name? It

    shouldn't

    include

    s3-<region>.amazonaws.com

    in it.

  • liorix
    4 weeks 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

  • denolfe
    Payload Team
    4 weeks 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?

  • dribbens
    Payload Team
    4 weeks ago

    @liorix Does it work if you remove the

    region

    setting?


    I've had this mess me up before.

  • liorix
    3 weeks 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?

  • dribbens
    Payload Team
    3 weeks ago

    @liorix, Is this still giving you trouble?


    forcePathStyle

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

Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More