Why can't I do ?


It works if the html file is local (on my C drive), but not if the html file is on a server and the image file is local. Why is that?

Any possible workarounds?

11/3/2010 7:11:13 PM

Accepted Answer

It would be a security vulnerability if the client could request local file system files and then use JavaScript to figure out what's in them.

The only way around this is to build an extension in a browser. Firefox extensions and IE extensions can access local resources. Chrome is much more restrictive.

11/3/2010 7:14:09 PM

shouldn't you use "file://C:/localfile.jpg" instead of "C:/localfile.jpg"?


Browsers aren't allowed to access the local file system unless you're accessing a local html page. You have to upload the image somewhere. If it's in the same directory as the html file, then you can use <img src="localfile.jpg"/>


C: is not a recognized URI scheme. Try file://c|/... instead.

Honestly the easiest way was to add file hosting to the server.

  • Open IIS

  • Add a Virtual Directory under Default Web Site

    • virtual path will be what you want to browse to in the browser. So if you choose "serverName/images you will be able to browse to it by going to http://serverName/images
    • Then add the physical path on the C: drive
  • Add the appropriate permissions to the folder on the C: drive for "NETWORK SERVICE" and "IIS AppPool\DefaultAppPool"

  • Refresh Default Web Site

  • And you're done. You can now browse to any image in that folder by navigating to http://yourServerName/whateverYourFolderNameIs/yourImage.jpg and use that url in your img src

Hope this helps someone


IE 9 : If you want that the user takes a look at image before he posts it to the server : The user should ADD the website to "trusted Website list".


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]