Programatically upload media

default discord avatar
7 months ago

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!


    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.