13

Here's the scenario: I have two machines on a LAN network. One of them is acting as a web server. When the second, client machine browser (Firefox) makes a request from the server, it sends the following html

<!DOCTYPE HTML>
<html>
<body>
<img src="C:\Users\General\Desktop\map1.jpg" align="middle">
</body>
</html>

The image however is not displayed. I have tried the following variations to the img tag:

<img src="C:/Users/General/Desktop/map1.jpg" align="middle">
<img src="file:///C:/Users/General/Desktop/map1.jpg" align="middle">
<img src="http://localhost//file:/C:/Users/General/Desktop/map1.jpg" align="middle">

Funny thing is if I view the page source and save the html content to a local file and open it in the browser it works. The exact same html code does not work when fetched from the server, but works when opened on the local machine.

Please note that I'm trying to load the image off the client machine because it is impossible to store an image on the server machine in my scenario. (The server is actually an Arduino Mega without an SD card)

6
  • So your image is on the local server right? Commented Jan 28, 2015 at 14:22
  • The image is on the client machine that makes the http request from the server machine Commented Jan 28, 2015 at 14:24
  • 1
    Map the drive to the server and put its mapped name in, so in Windows Explorer on the server, click Map Network Drive and map the client's C: to the server's E: and then put E:... in the HTML. Commented Jan 28, 2015 at 15:28
  • Nice one.. but the server is not a windows machine. It's an Arduino.. :( Commented Jan 28, 2015 at 16:07
  • 1
    Does this answer your question? How to show local picture in web page? Commented Nov 10, 2021 at 14:13

5 Answers 5

9

In most recent browsers, links to local files ( file:/// ) do not open, for security purposes. In your case, the browser does not display an image that resides on a file on your hard disk. This reason also explains why it works when you save your page locally.

Sign up to request clarification or add additional context in comments.

2 Comments

How can we fix it?
And why are images on your local machine less secure than images on the Internet? FireFox does not seem to have a problem with that...I am wondering here
1

For starter, you need to add the runat="server" attribute.

If that doesn't suffice, then:

you should change

<img src="http://localhost//file:/C:/Users/General/Desktop/map1.jpg"/>

to something like

<img src="http://localhost/General/Desktop/map1.jpg"/>

or even better to

<img src="~/General/Desktop/map1.jpg"/>

which targets the root of the application (you would need to move your image in that directory)

1 Comment

No luck with any of the changes
1

A html page cannot request images from the client host. It must be stored on the server, or in another remote location.

Comments

-2

If you are using Arduino you can:

  1. Use embedded css and images. In result you will got whole page by one browser call

  2. Add additional logic to process browser requests for getting css and jpg files from SD card filesystem of Arduino

Comments

-3

it can be solved like this:

.img-class
{
  background-image:url("../../resources/myImage.jpg");
  width: 100%;
  height: 100%;
}

<img  className='img-class'/>

1 Comment

this simply looks on the server filesystem, not client filesystem. sorry no tortilla

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.