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.

Programatically upload media

default discord avatar
xavierpacheco2 years 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") ,

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