Programatically upload media

default discord avatar
Xavier Pacheco
3 weeks ago
1

Hello, I am trying to seed my database and I am not being able to upload media. How could I do this?



Update: I managed to find the documentation, we need to insert the filePath outside the data; My final solution:


 const beer_image = await payload.create<Media>({
        collection: 'media',
        data: {
        description: "Seed Beer"
        },
        filePath: path.resolve(__dirname, "./seedingImages/beer.jpg") ,

      });
    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.