cant upload files to pocketbase

Im trying to update file object to pocketbase db using next14 with server actions, but I have trouble….
submit action:

const incrementStep = async (values) => {
        const data = new FormData()
        for(const[key, value] of Object.entries(values)){
            data.append(`${key}`, `${value}`)
        }
        data.append("file", values.PictureObject)
        StepOneDoctorAction(data)
        // setActiveStep((step) => step + 1)
    }

everything works ok, i recive responce to server component:

{
  Name: 'regregre',
  LastName: 'ergergerger',
  PhoneNumber: 'gergerger',
  LicenseNumber: 'ergregre',
  Nationality: 'Lietuvis',
  DateOfBirth: 'Wed, 18 May 2022 21:00:00 GMT',
  PictureObject: '[object File]',
  Gender: 'Vyras',
  file: File {
    size: 95222,
    type: 'image/png',
    name: 'hotel.png',
    lastModified: 1706257080088
  }
}

the last thing that i do, is submiting to pocketbase db:

try {
            const data = {
                "UserId": pb.authStore.model.id,
                "Name": val.Name,
                "LastName": val.LastName,
                "PhoneNumber": val.PhoneNumber,
                "LicenseNumber": val.LicenseNumber,
                "Nationality": val.Nationality,
                "BirthDay": dayjs(val.DateOfBirth).format("YYYY-MM-DD"),
                "Gender": val.Gender,
                "file:": val.file
            };
            await pb.collection('DoctorDetails').create(data);
        } catch (error) {
            return 
        }

and then i getting an error from pocketbase file: Missing required value.(i made field required)

I tried to modify request in different ways but had no luck

Leave a Comment