SAP Hybris email velocity template image reference - java

I have .vm file for confirmation order mail and I'm placing some informations to this .vm template. There are several images in these informations. But my images not rendered while the email was sending.
I tried several methods but doesn't work.These are:
<img src='${ctx.contextPath}/images/theme/social_01.jpg
<img src='${ctx.themeResourceUrl}/images/theme/social_01.jpg
and
<img src='../images/theme/social_01.jpg
Any one of these are didn't work for me.
Also my images at the following location of the project:
xxxStore > import > sampledata > contentCatalogxxx > images > theme >
How can I solve this problem ?

Can you print the complete image URL in the email and try to open it in the new browser window and see. You should able to access your image. If not, try looking at the URL, is it correct? Let me know the result.
I would suggest you to following any exiting working image, place your image to the same folder, and access it similarly.
It seems you are trying to access static image. You can find all frontend static content under the webroot folder of the storefront extension. Your image should be in the same folder as well.
e.g.
I have an image at
sastorefront/web/webroot/_ui/responsive/theme-blue/images/test.png
I can access it using
${themeResourcePath}/images/test.png
To debug path issues, I would print the path, and try hitting same URL through the browse. Ideally, an image should be accessible with the URL. Say in my case, I can access test.png with
https://example.com/_ui/responsive/theme-blue/images/test.png

You have to make sure that your image URL which you are using in VM is corresponding to the actual image URL.
To provide this,
go to Backoffice media type
check your media URL

Related

How to embed an image in email?

I am trying to write a Java program where I need to send an image to Gmail. I am sending the image as an embedded object.
<img src="data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAsCAYAAADmZKH2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABISURBVFhH7c4hAQAgEAAxEhGGZN8YOkwhTsxvnT33V+VUOVVOlVPlVDlVTpVT5VQ5VU6VU+VUOVVOlVPlVDlVTpVT5dTHubkPuMrNUFKjQWUAAAAASUVORK5CYII=">
Other mail service providers are showing it fine, but Gmail specifically is removing it, so it is not visible in the message.
How can I make it visible in Gmail as well as the other mail service providers?
Place the image in a publicly accessible server and give the url for src attribute instead of dataUrl.
It is not possible in Gmail, outlook etc. They ignore base64 images.
For further information follow the link at below.
https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/
There is an alternative way for doing this. Embed images in the email using the cid method. (Basically including the image as an attachment, and then embedding it).
https://www.campaignmonitor.com/blog/how-to/2008/08/embedding-images-revisited/

Froala Editor Java sdk Examples don't work

When I try to upload image with the exmaple given in the froala java sdk, the picture is stored in local storage but the picture disappear because the server have no access to the folder.
Error here:
froala upload image error 404
Just added new context in the Tomcat file server.xml to point to the folder images in the root of the server:
<Context docBase="images" path="" reloadable="true" source="your source"/>
Then in class File.class changed parameters in method FileUtils.copyInputStreamToFile to save images in this folder.
And I should add a Thread.sleep(5000) after Image.upload() call in UploadImage.java to display image otherwise it didn't work. I think there is a problem with synchronization between the upload and the http request GET which get the image.
So I didn't succeed to create my own servlet so I used those in froala sdk examples.
I tried to find where the http request GET is made in froala's javascript, to change the URL in http request but didn't find.
Didn't understand why the froala example didn't work but find how to make it works in other way.

smartgwt save image file instead show in browser

I've got a smartgwt application which create a link with a jpg/gif/png/pdf files. This files are shown in browser. I want to get the save dialog instead it which ask me the path when I want to save the file at local machine. How could I do that?
As I know, you have to change the response header by setting the Content-disposition to attachment. Like this:
'Content-disposition: attachment; filename=image.jpg'
'Content-type: image/jpeg'
With these the browser will understand most cases that it should show up a dialog to save the image with the name: image.jpg. Also it might offer you to send it directly to an application, for example to an image viewer.
To get it work from a simple link, perhaps you have to write a servlet which will return the requested file with the correct headers and call that servlet from every link with a parameter to the real file.

java servlets display image in html code

I have a servlet which returns as response an html page that also includes pictures. I have those pictures stored on the file system in the Pictures folder (path: /home/andrei/Pictures).
I currently have there just one photo(name: eu.jpg ) but i will add more.
So the point is that in the html code i somewhere have this: <img src="/home/andrei/Pictures/eu.jpg" alt="pic" > . But when i get the html page it doesnt display neither the photo nor the "pic" text from alt(not sure if this is normal...). I read that it may be due to the path i gave in src but i dont know exactly what to give.
So what path should i give to the src?
And is it normal not displaying the alt text because i knew that when it cannot load the pic it shows that text.
Additional information:
IDE : Eclipse Juno
SO : Linux
Server: Tomcat 7.0
Any image you intend to display in a browser connecting a web container (Tomcat in your case) must be visible in the container. To do it, place the images in the webapp/ folder and link them properly from the servlet generating the correct tag where path is the correct http link to your file.
When you send back the HTML response, the client's browser will render the document and then, send requests for additional resources in order to show the HTML document fully. That includes the images, so Tomcat must be able to serve them. If you can't put them in a folder inside WebContent from the beginning, the servlet must do the move and create the document specifying the "public route".
The images should be part of the webapp. Absolute FS path will not work. <img> will take relative path, or absolute path wrt the website.

Display Image on web page using Java

In my Java EE app, there is a function to upload images. When uploading an image, I'm saving image path in MySQL database.
Now I want to display uploaded image on a web page using image path that saved when uploading the image in my MySQL database table.
How could I do this ?
It depends. Is the path someplace that a web server is serving documents from? Then just include the path, adjusted as necessary, in an IMG tag. If not, or if the image data itself is actually in the database (you're not entirely clear about this) then create a servlet which returns the contents of an image based on query parameters, and use that servlet's URL (plus the query parameters) in the SRC attribute of the IMG tag.
Write a servlet that extracts your stored image from database and writes back into servlet outputstream.
You need to set the relevant mime type of the image, for example "image/jpeg", before writing into outputstream.
You need to point the image source to this servlet url with required input parameters to load the correct image from the database. For example :
<img src="http://mydomain/servlet/imageServlet?imgid=xyz" />
There is nice example given by BalusC at: ImageServlet serving from database

Categories