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

default discord avatar
SibergenomE
6 months 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
    Payload Team
    6 months 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
    SibergenomE
    6 months ago

    Thanks! That works perfect 🙂

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.