Cloud Storage Plugin: Nesting a document in dynamic subdirectories

default discord avatar
4 months ago

I am currently using the S3 adapter for handling documents for our clients. We are using a multi tenant structure for our CMS and therefore have many different clients accessing the same documents collection. As far as I have tested, the file is stored in AWS as the filename. I have prepended the client ID to the front of the filename (123...ABC/file_name.png) so that the file is stored in documents > client ID > filename and there are no conflict in our S3 bucket. It also allows the client docs to be segregated. The structure is right in S3 (pic 1) but the server can't locate the file because it says the key in invalid.

The prefix in my config is "documents" to match my collection (pic 2). It seems like payload cannot access a nested directory starting at the prefix directory. If I change the prefix to a specific client ("documents/123...ABC") it works, but I would rather not make separate collections for each clients documents just so that the prefix matches.

Lastly, even the key in AWS matches the URL but I still get an error saying the key is invalid (pic 3, 4, 5).

  • default discord avatar
    4 months ago

    This might not help, but in my own configuration of a custom prefix I included a


    at the end of the pathname

    so like

    prefix: 'media/',
  • default discord avatar
    4 months ago

    I tried that and got the same error

  • discord user avatar
    Payload Team
    2 months ago

    Hey @blupandaman did you find a solution here? do you still need help?

  • default discord avatar
    2 months ago

    I haven't found a solution yet as it seems to be an AWS sdk issue. Payload keys don't seem to register with AWS properly when getting the values through the sdk.

    I've just resorted to giving every file a unique name so there are no conflicts. I figured all organization can be handled through payload rather than having a structured bucket

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


Connect with the Payload Community on Discord



Can't find what you're looking for?

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