Assign uploaded file to specific file field

Hello,

Is it possible to assign a file uploaded from the frontend to a specific field defined in a page blueprint?

I use the createFile() to save the uploaded file but I cannot assign it to a specific file field. Here is the file field in the page blueprint:

  providerLogo:
    label: Logo
    type: files
    uploads: providerLogo
    max: 1

and I have a providerLogo blueprint in the files folder as follows:

title: Provider logo uploads

accept:
  mime: image/*
  type: image
  maxsize: 1000000

Thank you in advance for your help.

Once you have uploaded the file to the page, you can update the page ($page->update()) to store the file in the files field. Note that you have to provide an array of file uuids as value, because the data needs to be stored in yaml format.

Thank you for your quick response. In my example I tried the following and it didn’t work:

$page->update([
    'providerLogo' => $file->uuid()
]);

where $file is the response of the function createFile().

I just added a dash and it worked:

$page->update([
    'providerLogo' => '- ' . $file->uuid()
]);

That’s why I wrote above that you need to store an array of file UUIDs

$page->update([
    'providerLogo' => [$file->uuid()->toString()]
]);

This will take care of storing it as yaml (with the dash(es)) automatically.