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.

Is it possible to have multiple select a file fields when using the cloudStorage plugin?

default discord avatar
snackdexlast year
4

I was able to setup the cloudStorage plugin with the s3 adapter, and was wondering if it was possible to have multiple upload fields per collection. For example if i have a Candy collection. Could i upload multiple files, one for like "logo" the other for "nutrition facts"? I'm new to Payload, so please humble me

  • discord user avatar
    tylandavis
    last year

    A common way of doing this is to have a two collections: one for your uploads, and another for the documents that use them.



    So you could have a

    Media

    collection for uploads, and a

    Candy

    collection for the candies, and then add fields on the

    Candy

    collection that relate to your

    Media

    collection.



    Your

    Candy

    collection would look something like this:


    export const Candy = {
      slug: "candy",
      fields: [
        // Other fields here...
        {
          name: 'images',
          type: 'array',
          label: 'Images',
          fields: [
            {
              name: "candyImage",
              label: "Image",
              type: "upload",
              relationTo: "media",
            },
          ],
        },
      ],
    };
  • default discord avatar
    snackdexlast year

    that is so awesome! ok, so then if I were to have another collection like

    Store

    where I want to also upload files is the best practice to use the same

    Media

    collection?

  • discord user avatar
    tylandavis
    last year

    Yup, you can totally do it that way. Most people just use one, but you can also create multiple upload-enabled collections.



    If for whatever reason you wanted to do more than one, you would just want to make sure you add it to the cloudStorage plugin config.

  • default discord avatar
    snackdexlast year

    you've been so helpful thank you!

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..