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.

Anyone know how to upload data with to an 'Upload' type using localAPI feature?

default discord avatar
sibergenome2 years ago
2

I've gotten as far as figuring out how to use onInit() config option to run a script, and using the payload.create method from the docs, but I can't find any docs on how to use this with an Upload collection.


I've also found that the in the object supplied to

payload.create()

, the

data

field has a

files

field with type

fs.promises.FileHandle[]

. I've passed this type to payload but I get:



    at new ExtendableError (/home/loz/projects/tf-api/node_modules/payload/src/errors/APIError.ts:26:11)
    at new APIError (/home/loz/projects/tf-api/node_modules/payload/src/errors/APIError.ts:43:5)
    at new MissingFile (/home/loz/projects/tf-api/node_modules/payload/src/errors/MissingFile.ts:7:5)
    at generateFileData (/home/loz/projects/tf-api/node_modules/payload/src/uploads/generateFileData.ts:51:35)
    at create (/home/loz/projects/tf-api/node_modules/payload/src/collections/operations/create.ts:110:77)
[nodemon] app crashed - waiting for file changes before starting...
  • discord user avatar
    jesschow
    2 years ago

    Hi @sibergenome - to use

    payload.create

    on an upload-enabled collection you need to additionally define the

    filePath

    , for example:



        collection: 'uploads',
        filePath: '/filepath',
        data: {...}
      });
  • default discord avatar
    sibergenome2 years ago

    Thanks! That works perfect 🙂

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.