7

I include this in my velocity file. but it is not working,

< img src="cid:src/resources/imageContent.jpg" />
Ataur Rahman Munna
  • 3,887
  • 1
  • 23
  • 34
  • 1
    Welcome to StackOverflow. Please visit the [help] and read [ask] to learn how to use this site. We do not understand your question at all. – Jim Garrison Jan 10 '17 at 07:06
  • i have answered similar question here : https://stackoverflow.com/questions/42489968/how-can-i-display-image-in-velocity-template/64754819#64754819 – shubham kumar Nov 09 '20 at 15:52
  • i have answer similar question here - https://stackoverflow.com/questions/42489968/how-can-i-display-image-in-velocity-template/64754819#64754819 – shubham kumar Nov 09 '20 at 15:54
  • i have answer this here - [How can I display image in velocity template](https://stackoverflow.com/questions/42489968/how-can-i-display-image-in-velocity-template/64754819#64754819) – shubham kumar Nov 09 '20 at 15:56

2 Answers2

3

You can follow the guide here.

For example, try this in your Velocity template file:

<img src = "cid:${cid}" alt = "Foo">

And in your Java code, try:

URL url = new URL("image.png");
String cid = email.embed(url, "Foo");
Map model = new HashMap();
model.put("cid", cid);
kkmonlee
  • 379
  • 2
  • 16
1

When your server is running you can get path till server from request.getContexPath();

So here you just need to provide rest path of the image. I have done this for my demo application like this.

 <img border="0" alt="Test" src="${projectPath}/images/logo.jpg"/></a></td> 

Now you have to set value of projectPath to your projectPath which you can get by request.getContexPath();

Now create one Map in which you have to add Key which will keyword that you have used in .vm file. For this example, we have used projectPath.

 Map map = new HashMap<>();
 map.add("projectPath",request.getContexPath());
 map.add() // other value that you want to replace in vm file

After that create instance of VelocityContext load this map with constructor argument like this

 VelocityContext velocityContext = new VelocityContext(map);
Neo
  • 4,550
  • 6
  • 34
  • 51
Darshit
  • 361
  • 2
  • 13