media not uploading to S3 bucket (plugin-cloud-storage)

default discord avatar
olivier_vd
4 months ago
20

Dear all, I'm having trouble storing my media collection to an S3 bucket. I followed the instructions on the github repo.


these are my configurations:


- media collections:

https://github.com/oliviervd/cms-studios/blob/main/src/collections/Media.ts


- payload config :

https://github.com/oliviervd/cms-studios/blob/main/src/payload.config.ts
  • default discord avatar
    imcorfitz
    4 months ago

    Have you received any errors in the console that could be helpful?



    The IAM creds for your S3 bucket user - have they received sufficient permission to store data in your bucket? And have you made sure the correct bucket name is written in the permissions for the IAM role?

  • default discord avatar
    ngurajeka
    4 months ago

    Also, you may need to put the region on the configuration as well.

    image.png
  • default discord avatar
    olivier_vd
    4 months ago

    i've added a security policy to the user; still doesn't work though.


    what does the forcePathStyle do? Is it needed.



    {


    "Version": "2012-10-17",


    "Statement": [


    {


    "Sid": "VisualEditor0",


    "Effect": "Allow",


    "Action": "

    ",
    "Resource": [
    "arn:aws:s3:::{bucketname}",
    "arn:aws:s3::::{bucketname}/

    "


    ]


    }


    ]


    }



    in the console I'm getting a 404: not found error. I'm guessing my path isn't correct?

  • default discord avatar
    imcorfitz
    4 months ago
    forcePathStyle

    allows you to change how you fetch images again. Could be useful in cases where you have maybe fastly cdn or a custom image service proxy.



    Is the record created in Payload?

  • default discord avatar
    olivier_vd
    4 months ago

    yes it all works fine, it just doesn't store the file anywhere it seems.

  • default discord avatar
    imcorfitz
    4 months ago

    If you look in your S3 bucket through AWS management console - you don't see it there neither?

  • default discord avatar
    olivier_vd
    4 months ago

    no I checked



    do I need to use the user ARN as endpoint perhaps?

  • default discord avatar
    imcorfitz
    4 months ago

    I created a custom policy for an IAM user with following:


    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "s3:PutObject",
                    "s3:GetObjectAcl",
                    "s3:GetObject",
                    "s3:PutBucketAcl",
                    "s3:ListBucket",
                    "s3:DeleteObject",
                    "s3:GetBucketAcl",
                    "s3:GetBucketLocation",
                    "s3:PutObjectAcl"
                ],
                "Resource": [
                    "arn:aws:s3:::<bucket-name>",
                    "arn:aws:s3:::<bucket-name>/*"
                ]
            }
        ]
    }


    May be a permissions issue



    Also note the asterisk here

    "arn:aws:s3:::<bucket-name>/*"


    Also looks like you have too many colons here

    Screenshot_2023-05-28_at_18.15.44.png
  • default discord avatar
    olivier_vd
    4 months ago

    S3://bucket-name/ would this be the endpoint?

  • default discord avatar
    imcorfitz
    4 months ago

    no

  • default discord avatar
    olivier_vd
    4 months ago

    or do i need it like this;

    https://s3.region-code.amazonaws.com/bucket-name/key-name


    ok i guess that's the issue 🙂

  • default discord avatar
    imcorfitz
    4 months ago

    S3_ACCESS_KEY_ID="IAM_ACCESSKEY"


    S3_SECRET_ACCESS_KEY="IAM_SECRET_ACCESS_KEY"


    S3_BUCKET="bucket-name"


    S3_REGION="eu-west-2"


    S3_ENDPOINT="

    https://s3.eu-west-2.amazonaws.com

    "

  • default discord avatar
    olivier_vd
    3 months ago

    Ok that resolved the issue. Everything works fine now! Thank you for your patience and help 🙂

  • default discord avatar
    imcorfitz
    3 months ago

    Most welcome bud

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.