How do I view file:// images from http://localhost served pages in Firefox 11?

28,672
<img src="file:///localhost:8080/C://Users/me/IMG_1000.JPG">
<img src="file:///localhost/C://Users/me//IMG_1000.JPG">

If it's a server on 8080, you shouldn't be using file:// -- It's not a file. It should be http://localhost:8080/blah. I don't think it works this way, but the second (if it should work) would be file://localhost/c:/* - note the number of slashes. And the line above has an additional // where it should be /

<img src="file:///C://Users/me/IMG_1000.JPG">

Now that makes sense, though for that you'll be limited in the ability to access it because of the security restrictions.

user_pref("capability.policy.localfilelinks.sites", "localhost:8080");

That (probably) should work the the file:///c:/* stuff if the page is loaded from http://localhost:8080/*.

  • use http://localhost:8080/* - probably the best solution
  • Use a folder and make it all soft or hardlinks to the actual files to minimize disk usage and update issues.
  • Use a folder and synchronize using any one of a myriad of tools (rsync, etc)
Share:
28,672
Michael
Author by

Michael

Being an engineer with a vision is a curse. You see the world as it should be, and you have just enough skill and ability to delude yourself into thinking you can fix things, make them better, and bring about a better order. Problem is, nobody cares about doing things right. You'll never have fast and reliable because people are cheap. As a result I waste my spare time wrestling with problems that should not be hard. I spend an entire weekend trying to get code to work that's more important than anything I could ever achieve at my job during the week. I'm not an engineer because I enjoy or even find fulfillment in solving problems. I want to set things right, but my private struggle is that succeeding in solving a difficult problem is an embarrassment, a shame for all the time wasted fighting things not directly relevant to the task at hand. I'm an engineer because my mind commands me, drives me to fight against the subtle evil in the world, and I must either obey or give up my mind. What is subtle evil? Things like the fact that one cannot simply develop once and have code that will run equally well on a desktop computer or a mobile platform. That mobile platforms are second class citizens in the computing world when in fact they are just as Turing Complete. Steve Jobs once said - to paraphrase - that it was more important to start with what makes life easier for the user and work backwards. I disagree. Start with what makes life easier for the developer by virtue of the fundamentals sitting right, and let everything flow from that. You can't build a skyscraper starting with the penthouse.

Updated on May 25, 2020

Comments

  • Michael
    Michael almost 4 years

    I've got a server running on my localhost machine (port 8080) that is trying to create IMG tags to local files. But, the files do not appear in Firefox 11.

    I was originally create the image tag using Javascript, but since that failed I fell back to HTML to experiment with various ways of directly referencing the file. None of the following work:

    <img src="file:///localhost:8080/C://Users/me/IMG_1000.JPG">
    <img src="file:///localhost/C://Users/me//IMG_1000.JPG">
    <img src="file:///C://Users/me/IMG_1000.JPG">
    

    If I paste the last URL directly into the address bar, the image opens fine.

    I have followed the directions here:

    http://kb.mozillazine.org/Firefox_:_Issues_:_Links_to_Local_Pages_Don%27t_Work

    I have tried modifying both user.js, and prefs.js, both directly and via the about:config viewer.

    I got the correct path to the profile directory from Help -> Troubleshooting Information -> Profile Directory -> Open Containing Folder.

    The relevant lines added are:

    user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
    user_pref("capability.policy.localfilelinks.sites", "localhost:8080");
    user_pref("capability.policy.policynames", "localfilelinks");
    

    I originally put http:// in from of "localhost:8080", but Firefox removed that. I also tried just "http://localhost" and "http://127.0.0.1", but those did not work either.

    BUT... strangely enough, even though I entered them from about:config and can see them in prefs.js, I cannot see them from about:config! This makes me think that perhaps the information at mozillazine is out of date, after all it says the info is for "Firefox 1.5 and above" and I am using Firefox 11!

    Note: the reason I want to use file:// access is that I don't want to allow arbitrary access to the files on my machine. To explain a bit more: I've got an interface to a database, and all that is required to access the database is a password. That's fine because I want to allow database access outside my machine to anyone with the password, but the image files exist outside the database. In order to server up the files through the server (because the files that exist are dynamic) I would need to create a new CGI that takes some kind of identifier in the database, but since the user can access the DB they could inject any filename they wanted.

    Edit: Also, I can't window.open() the file URL either. What possible security benefit could that have?

  • Michael
    Michael about 12 years
    Two problems with this approach: 1. disk space (there are a LOT of files) 2. keeping everything synchronized
  • Michael
    Michael about 12 years
    Playing around with this a little bit, I am coming to the conclusion that Firefox 11 no longer supports the user_pref option.
  • Hans Ginzel
    Hans Ginzel over 7 years
    How to specify "capability.policy.localfilelinks.sites" if the page is not served by the local web server, but it is an directly opened html file?