on 11-27-2009 8:52 AM
Hi,
I have a sceanario where I want to access JPG image stored in dist/images folder inside JSPDynpage Component java file.
It is ok if I get it in the form of a byte array (byte[]).
Any idea how to achieve it?
Please help.
Thanks and regards,
Amey Mogare
>
> Hi,
>
> I have a sceanario where I want to access JPG image stored in dist/images folder inside JSPDynpage Component java file.
> It is ok if I get it in the form of a byte array (byte[]).
>
> Any idea how to achieve it?
>
> Please help.
>
> Thanks and regards,
> Amey Mogare
Hi Arney,
you can get the Path to it by using the following code:
//Suppose that request is an object of IPortalComponentRequest
IResource res = request.getResource(IResource.IMAGE, "images/myImage.jpg");
String url = res.getResourceInformation().getURL(request));
When you have the url you can either just display it in HTML via the img-Tag or you can also get a byte array by using standard Java classes/methods.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Clemens,
Thank you for valuable reply.
I tried your code and now I am getting following exception
java.io.FileNotFoundException: /irj/portalapps/Ameymypay/dist/images/draft.jpg (No such file or directory (errno:2))
This draft.jpg image is in dist\image folder in my PAR file named Ameymypay.
Thanks and regards,
Amey Mogare
>
> Hi Clemens,
>
> Thank you for valuable reply.
>
> I tried your code and now I am getting following exception
>
>
> java.io.FileNotFoundException: /irj/portalapps/Ameymypay/dist/images/draft.jpg (No such file or directory (errno:2)) >
>
> This draft.jpg image is in dist\image folder in my PAR file named Ameymypay.
>
> Thanks and regards,
> Amey Mogare
Hi Arney,
the above code works for my components... But I have two suggestions which you could try:
- I suppose that you have created an IView for your application. Check the isolation mode of this IView in PCD. If it is set to "URL isolated" then set it to "Embedded". With this setting it should work.
- If this is not possible (e.g. you want to keep the isolation mode as URL isolated or for any other reason) then just prefix the URL with your server host name like this:
//...
String myServerPrefix = "http://localhost:50000"; //suppose that this is your server
String url = res.getResourceInformation().getURL(request));
url = myServerPrefix + url;
This should also work. Of course you can also dynamically get your server name (or get it via portalapp configuration). But maybe you try the hard coding at first.
Hi Clemens,
Thank you. It worked.
For my surprise, Isolation mode of iView is Embedded, but still it wasn't working for me!
I tried your code and it worked!
IResource res = request.getResource(IResource.IMAGE, "images/draft.jpg");
String myServerPrefix = "http://mytest.com";
String url = myServerPrefix + res.getResourceInformation().getURL(request);
Now, can you tell me how to I get rid of this hard-coding server URL?
Thanks and regards,
Amey Mogare
>
> Hi Clemens,
>
> Thank you. It worked.
>
> For my surprise, Isolation mode of iView is Embedded, but still it wasn't working for me!
>
> I tried your code and it worked!
>
> IResource res = request.getResource(IResource.IMAGE, "images/draft.jpg"); > String myServerPrefix = "http://mytest.com"; > String url = myServerPrefix + res.getResourceInformation().getURL(request); >
>
> Now, can you tell me how to I get rid of this hard-coding server URL?
>
> Thanks and regards,
> Amey Mogare
Hi Arney,
maybe you should first also give the suggestion of ram another chance, because you can also use it in your class code:
String url = request.getWebResourcePath() + "/images/draft.jpg";
Otherwise to avoid the hardcoding you can either perform configuration in your portalapp.xml with the server prefix and read it out, or write a little method that retrieves your server name. This is however not as trivial as it might look like. I personally have a method like follows:
public String getBasePortalUrl(IPortalComponentRequest request) {
StringBuffer requestURL = request.getServletRequest().getRequestURL();
//Parse the server name,port etc. out of this request url, depending on your system environment
//Normally you parse till you get to /irj
}
Hi Clemens,
I tried Ram's suggestion but it gives
java.io.FileNotFoundException: /irj/portalapps/Ameymypay/images/draft.jpg (No such file or directory (errno:2))
I have written method as suggested by you and its working fine now.
public java.lang.String getBasePortalUrl(IPortalComponentRequest iPortalCompRequest) {
String requestURL = iPortalCompRequest.getServletRequest().getRequestURL().toString();
int indexOfIrj = requestURL.indexOf("/irj");
return requestURL.substring(0, indexOfIrj);
}
Thank you for help.
Thanks and regards,
Amey Mogare
Amey,
Here is the code to access a jpg image stored in the folder PORTAL-INF -> dist -> Images
<%=componentRequest.getWebResourcePath()%>/images/image_file.jpg%>
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.