Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load image from shared file on local server?

I am receiving data from local server backend and I want to be to load image. I am receiving array of object like this:

[ {
        "t_pdno": "SFC093989",
        "t_mitm": "SLS005251ACL-3382012763-1",
        "t_qrdr": 60,
        "Operations": "10,20,30,40,60,70",
        "path": "\\\\192.168.1.245\\Images\\ACL-3382012763-1.jpg"
    },
    {
        "t_pdno": "SFC093991",
        "t_mitm": "SLS005251ACL-3382012765-1",
        "t_qrdr": 120,
        "Operations": "10,20,30,40",
        "path": "\\\\192.168.1.245\\Images\\ACL-3382012765-1.jpg"
    },]

After I console.log(rowData.path) the path it looks like this:

\\192.168.1.245\Images\ACL-3382014766-1.jpg

So it is perfect to paste in browser and I get the image:

enter image description here

The problem is I cannot load it in my img tag. I tried:

<img
    src={process.env.PUBLIC_URL + rowData.path}
    alt={`${rowData.t_mitm}`}
     loading="lazy"
              />

<img
     src={rowData.path}
     alt={`${rowData.t_mitm}`}
     loading="lazy"
              />




  <img
      src={require(rowData.path)}
      alt={`${rowData.t_mitm}`}
      loading="lazy"
                  />



 <img
      src={`url(rowData.path)`}
      alt={`${rowData.t_mitm}`}
      loading="lazy"
                  />

and nothing is working. How can I load the images?

UPDATE:

If I install http-server to the \\192.168.1.245 server and host the Images folder there on specific port I am able to receive the image. But this mean that I will always have to keep folder hosted.

UPDATE 2:

If I try loading the image like this:

   <img
          src={`file://192.168.1.245/Images/${rowData.t_mitm}`}
          alt={`${rowData.t_mitm}`}
          loading="lazy"
                      />

It probably works but I get:

Not allowed to load local resource: file://192.168.1.245/Images/ACL-3382012763-1.jpg

like image 957
Borislav Stefanov Avatar asked Sep 17 '21 13:09

Borislav Stefanov


People also ask

How do I host photos locally?

To use an image on a webpage, use the <img> tag. The tag allows you to add image source, alt, width, height, etc. The src is to add the image URL. The alt is the alternate text attribute, which is text that is visible when the image fails to load.

How to get images from the server to the browser?

To fix this, all you need to do is create an ASHX handler page that fetches the images that are on the server's local drive or network and serve them as an image to the browser: Show activity on this post. 1) Why the proxy page can access the physical path but other page cannot able to access it ? The other page can.

Can the shared folder be moved from inetpub?

The shared folder is NOT in the INETPUB folder and it cannot be moved. The directory structure of the shared folder is similar to the following: In this scenario, the IMAGES folder is shared as "IMAGES" to Everyone and IUSR.

How to access an image from an external folder?

You need to create a virtual directory to the folder where the image is located and access using "External" option rather than "Embedded" mode. Then we can access the image using http://sitename/imagefolder/abc.jpg

How to share files using Apache server from computer?

But here we are going to discuss sharing files using Apache Server from your computer. Your system has to be connected to a LAN for Accessing the files from one computer to another connected on a LAN. The local server is the same as our web server. As our Web Server serves our needs anywhere and anytime.


Video Answer


1 Answers

Despite browsers supporting file:// to open local files the support ends here. It is considered a security violation to open a local file within a webpage. This is why your system is not working.

Solutions:

  • The canonical solution would be to have a system serve your local folder as http://
  • If you do not like the idea of serving the folder and if you have control over the browser using your "website" you may attempt to start a browser with security features disabled (for Chrome you may try --allow-file-access-from-files and --disable-web-security flags)
like image 114
Newbie Avatar answered Oct 29 '22 01:10

Newbie