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

default discord avatar
snackdex
6 months ago
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
    Payload Team
    6 months ago

    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
    snackdex
    6 months ago

    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
    Payload Team
    6 months ago

    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
    snackdex
    6 months ago

    you've been so helpful thank you!

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.