I'm using Thymeleaf with Spring Boot.
I'm trying to send a mail with a html template.
The mail is ok, the variable thymeleaf in the template are replace it's perfect, but, my only one problem is that the image are not displayed. It's just like if the image doen't exist.
The html template and the image ( Picture.png ) are on the same folder.
In the template I have try these multiples tries :
<img src="Picture.png" />
<img src="#{Picture.png}" />
<img th:src="|cid:${imageName}|" /> // by passing the "Picture.png" in the imageName variable
<img th:src="#{Picture.png}" />
But nothing is working, I need help thanks !
I answer my own question because I suceed to resolve the problem :
Just put like that <img src="cid:imageName"/> in the html file
Checkout the Thymeleaf's documentation especially the part for context-relative and server-relative url patterns.
If your project root directory is called myapp and you deploy it into a Tomcat server, your application will probably be accessible as http://localhost:8080/myapp, and myapp will be the context name.
So assuming the folder containing both the image and the html is located at:
myapp/resource/assets/(html and Picture.png exists)
the correct code to dynamically fetch the image is:
<img src="resource/assets/Picture.png" th:src="#{resource/assets/Picture.png}" />
I have a scaffold which is used to update frontend information of the Home# Index. I'm unable to add the image int he given theme formate.
<section id="home" class="no-padding parallax mobile-height wow fadeIn" data-stellar-background-ratio="0.5" style="background-image:url(<%= image_tag detail.banner.url %>);">
Thanks.
It seems that details.banner.url evaluates to external url of placehold.it/1920x1200. If that's where the image is (which I doubt) you have to add http:// to the link, because right now it is looking for a placehold.it folder and not server address. If you're trying to read a file from your server, details.banner.url clearly returns the wrong path. If you want to put the image in the database then look into ActiveStorage or Paperclip.
Please go through this rails guide for asset pipeline
According to this guide, your code will be like this:
style="background-image:url(<%= asset_path detail.banner.url %>);"
I am trying to build HTML in my MFC application using class CHtmlEditView.
So I want to add an image, currently I am using <img align=\"baseline\" alt=\"\" src=\"C:\\cry.png\" border=\"0\" hspace=\"0\"> and its working all fine.
Now, I have to replace this src=\"C:\\cry.png\" local path. So I have added this to resources and <img align=\"baseline\" alt=\"\" src=\"\\res\\smiley.png\" border=\"0\" hspace=\"0\"> its not getting image path. I am not sure how to give a path a image from resources. I have seen LoadBitmap() and LoadImage() but do know how to get a relative path of resource.
Your target URL will be something like this: res://yourapplication.exe/agent.png
Please note that you will need to import your image resources just like this:
Go to Resource View
right click and select Import context menu option
select your image file
Please note that as the result you should have the following in your .rc file:
STARTPAGE.HTML HTML "res\\startpag.htm"
AGENT.PNG HTML "res\\agent.png"
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?
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.
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
we can use javascript's FileReader() and it's readAsDataURL(fileContent) function to show local drive/folder file.
Bind change event to image then call javascript's showpreview function.
Try this -
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;'>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
function showpreview(e) {
var reader = new FileReader();
reader.onload = function (e) {
$("#previewImage").attr("src", e.target.result);
}
//Imagepath.files[0] is blob type
reader.readAsDataURL(e.files[0]);
}
</script>
</head>
<body >
<div>
<input type="file" name="fileupload" value="fileupload" id="fileupload" onchange='showpreview(this)'>
</div>
<div>
</div>
<div>
<img width="50%" id="previewImage">
</div>
</body>
</html>
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".
Newtang's observation about the security rules aside, how are you going to know that anyone who views your page will have the correct images at c:\localfile.jpg? You can't. Even if you think you can, you can't. It presupposes a windows environment, for one thing.
if you use Google chrome browser you can use like this
<img src="E://bulbpro/pic_bulboff.gif" width="150px" height="200px">
But if you use Mozila Firefox the you need to add "file " ex.
<img src="file:E://bulbpro/pic_bulboff.gif" width="150px" height="200px">
starts with file:/// and ends with filename should work:
<img src="file:///C:/Users/91860/Desktop/snow.jpg" alt="Snow" style="width:100%;">
I see two possibilities for what you are trying to do:
You want your webpage, running on a server, to find the file on the computer that you originally designed it?
You want it to fetch it from the pc that is viewing at the page?
Option 1 just doesn't make sense :)
Option 2 would be a security hole, the browser prohibits a web page (served from the web) from loading content on the viewer's machine.
Kyle Hudson told you what you need to do, but that is so basic that I find it hard to believe this is all you want to do.
If you're deploying a local website just for yourself or certain clients, you can get around this by running mklink /D MyImages "C:/MyImages" in the website root directory as an admin in cmd. Then in the html, do <img src="MyImages/whatever.jpg"> and the symbolic link established by mklink will connect the relative src link with the link on your C drive. It solved this issue for me, so it may help others who come to this question.
(Obviously this won't work for public websites since you can't run cmd commands on people's computers easily)
I have tried a lot of techniques and finally found one in C# side and JS Side.
You cannot give a physical path to src attribute but you can give the base64 string as a src to Img tag.
Lets look into the below C# code example.
<asp:Image ID="imgEvid" src="#" runat="server" Height="99px"/>
C# code
if (File.Exists(filepath)
{
byte[] imageArray = System.IO.File.ReadAllBytes(filepath);
string base64ImageRepresentation = Convert.ToBase64String(imageArray);
var val = $"data: image/png; base64,{base64ImageRepresentation}";
imgEvid.Attributes.Add("src", val);
}
Hope this will help
background-image: url(${localImage});
If you want to add a file as background to your website locally.
You need to upload the image aswell, then link to the image on the server.
what about having the image be something selected by the user? Use a input:file tag and then after they select the image, show it on the clientside webpage? That is doable for most things. Right now i am trying to get it working for IE, but as with all microsoft products, it is a cluster fork().
I have the following HTML component, trying to display a local image, however it will not show up whether I use <img src="file:/tmp/img.png"> or <img src="/tmp/img.png" />. Any ideas why this doesn't work? Saving the file to a local file and opening it works fine!
var xhtml:XML = <html>
<body>
<img src="file:/tmp/logo.gif" />
</body>
</html>;
myhtml.htmlText = xhtml.toXMLString();
Update:
This works fine, btw, if I save the same xhtml to a file and use webkit to open that file using myhtml.htmlLoader.load(new URLRequest("file:///path/to/html/file")).
Did you check for security sandbox violation?
Also did you try with "tmp/img.png" and "./tmp/img.png"?
Or maybe Air doesn't support xhtml, I'm not sure. Try and remove the slash in the img tag like this:
myhtml.htmlText = "<html><body><img src=\"tmp/logo.gif\"></body></html>";
Did you check for any javascript error in other parts of you webpage? They might be preventing your webpage to open.
Syntax looks OK for embedding image, check it here:
http://www.w3schools.com/htmL/tryit.asp?filename=tryhtml_images2