If a user uploads a file other than a PDF file, we're already throwing an error:

Only PDF files are supported, and they must end in .pdf.

However, we should give the user (or actually the browser) a hint in advance, which file types are accepted, see #3032701: Give browsers a hint which file types are accepted as uploads and #3031371: Add allowed file extensions as 'accept' attribute for file uploads to improve UX issues for Core. While it's not in our hands whether the browser turns that hint into a useful filter, at least Firefox, Chromium and Opera do so, while most mobile browsers simply ignore the 'accept' parameter, unless it's 'image/*'. Implementation will improve over time though, as it's a web standard.

While Core goes by extension and most browsers simply turn IANA (aka MIME) types into extensions, too, rather than actually checking the file content, we should choose 'application/pdf' for a more standards-conform approach.

Comments

Pancho created an issue. See original summary.

pancho’s picture

Status: Active » Needs review
StatusFileSize
new8.18 KB
new8.34 KB
new7.27 KB
new8.3 KB
new7.05 KB
new7.25 KB
new1.49 KB

Enclosed patch adds IANA type 'application/pdf' as accept attribute to our <input type='file'>.

I also slightly reworded 'title' and 'description' in order to better convey that while we're using the PDF file as a template, it's not like the user needs to upload a special "PDF template" (a concept that exists for DOCX vs. DOTX and XLSX vs. XLTX files, e.g. A regular .PDF file will do, it only has to contain fillable form fields.

Also, the titles weren't translatable. (All other instances of non-translatable user-facing text need to be covered in a dedicated followup.)

Here's how it looks like before and after the patch:

New PDF file (before):
New (before)
New PDF file (after):
New (after)

Update PDF file (before):
Update (before)
Update PDF file (after):
Update (after)

File dialog (Firefox 65/KDE/Linux, before):
Dialog (before)
File dialog (Firefox 65/KDE/Linux, after):
Dialog (after)

pancho’s picture

Priority: Normal » Minor
StatusFileSize
new3.87 KB
new2.39 KB

Added tests plus fixing some docblocks. Should still be green.

  • Pancho committed 48dcc6d on 8.x-4.x
    Issue #3039043 by Pancho: Give browsers a hint we're only accepting PDF...
pancho’s picture

Version: 8.x-4.x-dev » 7.x-1.x-dev
Status: Needs review » Patch (to be ported)
Issue tags: +Novice

Patch #2 (not #3) may be ported to 7.x-1.x-dev. An easy task for novices.

pancho’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new802 bytes

For convenience, here's a manually tested patch against 7.x-1.x.

bramdriesen’s picture

Status: Needs review » Reviewed & tested by the community

Looks ok :)

  • Liam Morland committed 4f33af3 on 7.x-1.x authored by Pancho
    Issue #3039043 by Pancho, BramDriesen, Liam Morland: Set 'accept'...
liam morland’s picture

Title: Give browsers a hint we're only accepting PDF files » Set 'accept' attribute on PDF upload controls
Component: Code » User interface
Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.