Message Boards
How t0 get Image from resource folder in Module Project ???
Fazalmahammad Babaria, modified 5 Years ago.
How t0 get Image from resource folder in Module Project ???
New Member Posts: 16 Join Date: 2/26/19 Recent Posts
hello,
I am trying to get image from resource folder but its not getting with same path i am able to fetch image but in render method i can't , so anybody have idea that how we can get image from resource folder of module project in our render method. and the code is as below for getting image
" ClassLoader classLoader = getClass().getClassLoader();
File file = new File("IMG/child2.jpeg"); "
thanx in advance
I am trying to get image from resource folder but its not getting with same path i am able to fetch image but in render method i can't , so anybody have idea that how we can get image from resource folder of module project in our render method. and the code is as below for getting image
" ClassLoader classLoader = getClass().getClassLoader();
File file = new File("IMG/child2.jpeg"); "
thanx in advance
David H Nebinger, modified 5 Years ago.
RE: How t0 get Image from resource folder in Module Project ???
Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Instead of doing the 'new File() thing, you just load the stream and use it:
InputStream is = classLoader.getResourceAsStream("/META-INF/resources/IMG/child2.jpeg");
But getting your own image kind of means the code is doing way more than it needs to (or is a sign that you're doing things wrong in general). Using an <img /> tag back to your own context would serve up the image w/o going through the stream handler.
InputStream is = classLoader.getResourceAsStream("/META-INF/resources/IMG/child2.jpeg");
But getting your own image kind of means the code is doing way more than it needs to (or is a sign that you're doing things wrong in general). Using an <img /> tag back to your own context would serve up the image w/o going through the stream handler.