Html Image Source from UNC Path

I need to set the image source to a network location.

The image is located in machineName \ mappedPath \ abc.jpg.

It does not load in any browser, although all I need for it to work is IE v9 and higher. When I check the location in the source, it is set to

<img src="\\machineName\mappedPath\abc.jpg">

When I right-click on the image placeholder in IE and look at the properties that I see, the address matters

file://machineName/mappedPath/abc.jpg

Using File Explorer with any of these paths opens the image in order.

I tried to add an IP. Cannot add domain name as non-domain.

Other ways I tried to set the source directly below. I read a few places that require 5 forward slashes, but that didn't make any difference.

<img src="file://\\machineName\mappedPath\abc.jpg">
<img src="file:////\\machineName\mappedPath\abc.jpg">
<img src="file://///\\machineName\mappedPath\abc.jpg">
<img src="file:////machineName/mappedPath/abc.jpg">
<img src="file://///machineName/mappedPath/abc.jpg">
<img src="\\machineName\mappedPath\abc.jpg">

,

https://blogs.msdn.microsoft.com/windows_azure_connect_team_blog/2011/01/20/windows-azure-connect-use-case-enable-file-sharing-on-windows-azure-vm/

, ?

, , https://jonlabelle.com/snippets/view/html/create-html-link-to-unc-path, ( IE)

+4
4

. .

:

FireFox , MVC, HtmlHelper.

public static class ImageHelper
{
    /// <summary>Converts a photo to a base64 string.</summary>
    /// <param name="html">The extended HtmlHelper.</param>
    /// <param name="fileNameandPath">File path and name.</param>
    /// <returns>Returns a base64 string.</returns>
    public static MvcHtmlString PhotoBase64ImgSrc(this HtmlHelper html, string fileNameandPath)
    {
        var byteArray = File.ReadAllBytes(fileNameandPath);
        var base64 = Convert.ToBase64String(byteArray);

        return MvcHtmlString.Create(String.Format("data:image/gif;base64,{0}", base64));
    }
}

MVC View :

using 
<img src="@Html.PhotoBase64ImgSrc(image)" height="60px" width="60px" alt="photo" />

"" @Html.PhotoBase64ImgSrc () UNC, .

//Photos/ebaebbed-92df-4867-afe8-0474ef8644eb.jpg
+1

( "file://" ), ( , ), localhost, , !), , UNC-, , UNC .

?

<img src="file://localhost/\\machineName\mappedPath\abc.jpg">
+2

3 ://:

<img src="file://///machineName/mappedPath/abc.jpg">
+1

NAS. , , . - -. :

  • IIS
  • IIS 7.0
  • : <img src="/virtualdir/picture.jpg" \>

// \,////, IP, ... .

, , /- \\IE-NAS-01\Data\Pictures, . , , PHP , .

, HTML wwwroot - . , "" wwwroot.

,

: : - # 13421784 - fooobar.com/questions/360409/...

php:

<img src="http://path.to/this/file.php"/>

file.php:

<?php
header('Content-Type: image/jpeg');
readfile('path/to/image.jpeg');

, ! !

PS: Content-Types:

header('Content-Type: image/gif');
header('Content-Type: image/jpeg');
header('Content-Type: image/png');
0
source

Source: https://habr.com/ru/post/1684364/


All Articles