Save files to folder

I’m trying to make kirby save files custom folder: /content/client_files.

  1. I created blueprint "/site/blueprint/files/client_file.yml
title: Image

accept:
  mime: .csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel

fields:
  alt:
    label: Alt Text
    type: text
    width: 1/2
    required: true
  caption:
    label: Caption
    type: textarea
  1. I created blueprint “/site/blueprint/pages/client_files.yml” - it will be parent.
title: Client files
# preset: page
  1. I created templates “client_file.php” and “client_files.php” in /site/templates/ directory (I’m not sure, if they are required).
  2. I created folder /content/client_files
  3. I created file /content/client_files/client_files.txt
  4. I created blueprint tab in site.yml:
tabs:
<...>
  files:
    label: Client files
    fields:
      client_file:
        type: files
        label: Downloads
        multiple: true
        translate: false
        uploads:
          parent: client_files
          template: client_file

When I try to upload file, I get error that file can not be created on null. If I comment #parent: client_files, then the file is uploaded to /content. What I’m missing? I can not find documentation, how could I do this in the correct way.

You have to provide a page object as parent:

parent: kirby.page('client_files')

Thank you, it works.

But when file is deleted from panel - it is not deleted in content folder. Is this by design, or should I turn on some option for deleting it from content too?

You are using a files field and therefore when you remove the file from the field, it is only removed from the field value in the content folder. You would have to go to the file view to actually delete the file.

If you don’t want to explicitely select a file out of a set (which is the purpose of the files field), consider using a files section instead.

1 Like

thank you