Do I need to do anything special to upload epub files?

So, yeah, I’ve created a new blueprint /site/blueprints/files/epub.yml with the following content:

title: EPUB
accept:
  extension: epub

I also have tried with the mime type:

title: EPUB
accept: application/epub+zip

In my files field I’m using:

type: files
required: false
multiple: false
layout: list
label: EPUB
image: false
template: epub

But I’m still getting the following error:

What I’m doing wrong? :thinking:
Thanks!

I suspect this is because Epub is not on Kirbys built in list of accpetable mime types.

I think probably you would need to make a pull request or wait for the team to add it for you.

You can register custom file types: File types | Kirby CMS

Oh neat didnt realise that got added to 3.6 :slight_smile:

Oh, that works fine! Now I can upload epub files… although, now I have another issue. The upload option correctly limits by mime type. But, when clicking on select to select one from my already uploaded files, it let’s me select any file.

I suppose this is ripe for a GitHub issue? Or am I missing something?

You can limit what you can select in a field with a query, either by template (the template you assign to these epub files) or by file type or extension.

See also: Files | Kirby CMS

Do you have an example at hand on how to filter by mime? or file template? I’ve tried the following but it’s not working:

query: page.files.template('epub')
query: page.files.filterBy('template', 'epub')
query: page.documents.filterBy('template', 'epub')

I’ve a /blueprints/files/epub.yml file… that’s what template means, no? My blueprints:

# Files field
type: files
required: false
multiple: false
layout: list
label: EPUB
image: false
uploads: epub
query: ????

# /blueprints/fields/epub
title: EPUB
accept: application/epub+zip

Thanks!

Ok, this works:

query: page.documents.filterBy('extension', 'epub')

I find surprising that template is not working though. It’s like it doesn’t know the type of template has each file… where is this info stored? In the .txt file next to the file? :thinking:

But do you assign this template anywhere in your files section?

filterBy('mime', `mimetypehere`)

should also work

1 Like

I don’t know what you mean. I’m using uploads: epub, which references to the epub file blueprint. Isn’t that enough to tell it that the uploaded file is of that type? :innocent:

Yes, sorry, didn’t look closely, thought you were uploading through a separate section not the field itself.

If all files have that template, then the query

query: page.files.template('epub')

Should work-

For some reason that doesn’t work for me. I have a couple of upload fields, so maybe that’s why it isn’t working??

image

I was imagining that the “template” type information would be attached next to the file .txt metadata. Or maybe it would be part of the file name… I don’t see neither of those.

The template is written in the file metadata file, exactly. Note that the template is only assigned at upload, not when you add files through the file system or added the uploads: epub property later.