User Tools

Site Tools


doc:appunti:linux:tux:mimetype

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
doc:appunti:linux:tux:mimetype [2020/09/13 19:42] – [Application associated to a MIME Type] niccolodoc:appunti:linux:tux:mimetype [2020/09/23 21:42] – [Application associated to a MIME Type] niccolo
Line 153: Line 153:
 ===== Application associated to a MIME Type ===== ===== Application associated to a MIME Type =====
  
-To view if there is an application associated with our custom MIME Type, we can run the following command:+To view if there is an application associated with our custom MIME Type, we can run the following command. No result is returned, as we can expect:
  
 <code> <code>
Line 159: Line 159:
 </code> </code>
  
-No result is returned, as we can expect.+We check also the behaviour of the **Firefox** browser, we prepare an HTML file containing this (notice the **anchor** tag uses the **type** attribute to declare the proper MIME type): 
 + 
 +<code xml> 
 +<a href="playlist.m3u" type="application/x-image-playlist">Image Slideshow</a> 
 +</code> 
 + 
 +Once clicked the link, Firefox displays the //Open with...// dialog box suggesting to use **VLC** to open the **MPEG Audio URL**.  If you click over the //Other...// option, Firefox says **No applications found for "M3U Images Playlist" files**. The MIME Type is recognizedbut the application to handle it is unknown. 
 + 
 +Now we prepare a file and save it as **/usr/local/share/applications/photo-reframe.desktop**: 
 + 
 +<file> 
 +[Desktop Entry] 
 +# The format of this file is specified at 
 +# http://standards.freedesktop.org/desktop-entry-spec/1.0/ 
 +# The entries are in the order they are listed in version 1.0 
 +Type=Application 
 +# This is the version of the spec for this file, not the application version. 
 +Version=1.0 
 +Name=Photo-Reframe 
 +GenericName=Image Viewer 
 +Comment=Slideshow with on-the-fly image cropping 
 +Icon=image 
 +TryExec=photo-reframe 
 +Exec=photo-reframe --fullscreen --play %f 
 +Terminal=false 
 +MimeType=application/x-image-playlist; 
 +# Category entry according to: 
 +# http://standards.freedesktop.org/menu-spec/1.0/ 
 +Categories=Graphics;2DGraphics;RasterGraphics;Qt; 
 +</file> 
 + 
 +then we run the **update-desktop-database** over that directory (it will update the **mimeinfo.cache** file in the same directory): 
 + 
 +<code> 
 +update-desktop-database /usr/local/share/applications/ 
 +</code> 
 + 
 +Something good has happened; the system knows how to handle that MIME type: 
 + 
 +<code> 
 +xdg-mime query default application/x-image-playlist 
 +photo-reframe.desktop 
 +</code> 
 + 
 +After this step, Firefox suggests to use **Photo-Reframe (default)** to handle the link, you can check the box **Do this automatically for files like this from now on** and the associated application will be launched automatically whenever you will click over a link like thisOnly after this association, you can open the Firefox **Preferences** => **Applications** and browse for the //M3U Images Playlist// and assign the preferred action. 
 + 
 +**NOTICE**: You may need to use **Shift-Click** to force the reloading of the link, otherwise Firefox may get the object from the cache, where the MIME type is cached too. 
 +===== Useless recipes ===== 
 + 
 +There are many recipes to add a new MIME Type and an associated applications, many of them suggest to edit some system files. In our experience it is **absolutely useless to modify** the following files: 
 + 
 +  * /etc/mailcap 
 +  * /etc/mime.types 
 +  * $HOME/.mozilla/firefox/<profile>.default/mimeTypes.rdf 
 +  * $HOME/.mozilla/firefox/<profile>.default/handlers.json 
 + 
 +===== Opening local files from an HTTP page ===== 
 + 
 +For security reasons a web browser does not allow to open a **%%file://%%** link from a page loaded via a network protocolo, like **%%http://%%**. This is obvious because you don't want to allow a remote sito to fiddle with objects stored on your local disk. But for our application we need this indeed: a page loaded from **%%http://localhost/gallery.php%%** must execute a local program passing a local file path to it, something like **/home/data/directory/playlist.m3u**. 
 + 
 +The link on the HTML page will look something like this: 
 + 
 +<code html> 
 +<a href="file:///home/data/directory/playlist.m3u"> 
 +    <img src="directory/folder.jpg"> 
 +</a> 
 +</code> 
 + 
 +To bypass the Firefox restriction, you have to create an **user.js** file in your profile directory, something like **$HOME/.mozilla/firefox/3e4ghyw2.default/user.js** (tested with Firefox 68.4): 
 + 
 +<code javascript> 
 +user_pref("capability.policy.policynames", "localfilelinks"); 
 +user_pref("capability.policy.localfilelinks.sites", "http://localhost"); 
 +user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess"); 
 +</code> 
 + 
 + 
 ===== Web References ===== ===== Web References =====
  
Line 166: Line 243:
   * **[[https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types|MIME types (IANA media types)]]**   * **[[https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types|MIME types (IANA media types)]]**
   * **[[https://www.december.com/html/spec/mime.html|MIME Types]]**   * **[[https://www.december.com/html/spec/mime.html|MIME Types]]**
 +  * **[[http://kb.mozillazine.org/Links_to_local_pages_do_not_work|Links to local pages do not work]]**
doc/appunti/linux/tux/mimetype.txt · Last modified: 2020/09/23 21:43 by niccolo