#Upload file using localAPI throwing an error [cause]: null

2 messages · Page 1 of 1 (latest)

wintry shore
#

Hey,
i have this "candidate" collection that has an upload type:

{
  ...
  type: 'collapsible', // required
  fields: [
    {
      name: 'degree',
      type: 'upload',
      relationTo: 'documents',
      access: {
        read: () => true,
        create: () => true,
        update: () => true,
       ....

this documents is also a collection:

export const Documents: CollectionConfig = {
slug: 'documents',
access: {
read: () => true,
create: () => true,
update: () => true,
delete: () => true,
// other access control...
},
admin: {
useAsTitle: 'name', // Add this line
},
upload: {
//staticURL: "/media",
adminThumbnail: 'small',
staticDir: 'documents',
mimeTypes: ['application/pdf'],
},
fields: [
{
name: 'name',
type: 'text',
},
],
}

if i create a candidate or a document through the admin panel, everything works fine.
but if i try to create a document through the localAPI, it throws the following error.

This is the currrent implementation for the document creation:

try {
debugger
console.log('degree', degree)

  const document = await payload.create({
    collection: 'documents',
    data: {
      name: degree.name,
    },
    locale: 'pt',
    file: degree,
  })
  return document.id
} catch (error) {
  console.error('Error creating document:', error)
  return null
}

please help

supple eagleBOT