3

When saving images from Twitter, then these images are sometimes saved with the extension .jpg-large when using Google Chrome (Chromium Issue 172529).

I was wondering if it is still possible to select these images in the file explorer when chosing an image via an input element?

My input element is this:

<input 
  accept="image/jpeg, image/png, image/bmp, image/gif"
  data-bind="file_select: upload_images" 
  multiple="multiple" 
  type="file"     
/>

I checked the MIME type of the image-large file and it is image/jpeg:

enter image description here

So the browser should be able to display it in the file dialog but in fact it's hidden:

enter image description here

Is there a way to display this custom file extension?

Kara
  • 6,115
  • 16
  • 50
  • 57
Benny Code
  • 51,456
  • 28
  • 233
  • 198

2 Answers2

3

According to HTML Living Standard by WHATWG (not to be confused with W3C) the accept attribute is not restricted to MIME types—it'll also accept file extensions:

A string whose first character is a U+002E FULL STOP character (.)
Indicates that files with the specified file extension are accepted.

In your case:

<input 
  accept="image/jpeg,image/png,image/bmp,image/gif,.jpg-large"
  data-bind="file_select: upload_images" 
  multiple="multiple" 
  type="file"     
/>

I've used it myself and I can tell you all major browsers support it, though user interface varies (I particularly find Firefox's implementation cleaner).

Please note that OS file chooser will normally filter by file extension, it won't inspect actual file contents to guess the MIME type—at least on desktop computers.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
1

I don't think that's possible. The specification says that you can only define by MIME type. So there's no way of saying e.g. "*.jpeg-large".

In theory, the OS should know the file type without resorting to sniffing file extensions.

That's how it works on Android. A file saved with .jpeg-large is able to be selected when used with accept="image/*"

Terence Eden
  • 14,034
  • 3
  • 48
  • 89
  • I always get lost in the sea of drafts, recommendations and working documents... but your document is from May 2013. Is it current standard? – Álvaro González May 31 '16 at 10:54
  • W3C allows only MIME types (https://www.w3.org/TR/html-markup/input.file.html#input.file.attrs.accept) and WHATWG allows MIME types and file extensions (https://html.spec.whatwg.org/multipage/forms.html#attr-input-accept). Choose your weapon! :D – Benny Code May 31 '16 at 11:37
  • Yes, of course... They are different organisations thus they produce different documents... I found this: [W3C vs WHATWG. Which gives the most authoritative spec?](http://stackoverflow.com/questions/6825713/html5-w3c-vs-whatwg-which-gives-the-most-authoritative-spec). Thank you! – Álvaro González May 31 '16 at 14:24