How can I upload files to a collection

default discord avatar
Japineda16
5 months ago
12

Hi! I need to upload a list of products, using the API, I'd like to know if exist some way to upload files directly to a POST query? I'd like to add saying that file file structure is contained in an array in my collection in PayloadCMS



I’ve reed the official doc of upload in payload, but it didn’t work, what am I doing wrong?

  • default discord avatar
    Jarrod
    5 months ago

    You need to post the file data to the media collection first, which will return an ID, and then you can use that on your array field

  • default discord avatar
    taongaB
    5 months ago

    please help, this is exactly what i am trying





    however, in payload, my image is :



    grayed out

    image.png
    image.png
  • default discord avatar
    Jarrod
    5 months ago

    @taongaB you are posting that data? try:


    photos: ["64381f9003fd801b47d54391"]
  • default discord avatar
    taongaB
    5 months ago

    hey thanks for your reply. The screen capture is from Postman. The challenge is that when i try without specifying the id, i get this error:





    this is how i defined the field:





    found the solution:

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