cancel
Showing results for 
Search instead for 
Did you mean: 

Open an image in new external window...

Former Member
0 Kudos

Hi all,

I have an image in the server, say "c:\hai.jpg", through my application i want to open this image in a new external window on click of a button.

I used the following code,


		String file ="C:\images\p.JPG";

		final byte[] content = this.getByteArrayFromResourcePath(file);

		final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.JPG_IMAGE);
		resource.setResourceName("p."+resource.getResourceType().getFileExtension());
		try 
		{ 
			final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getAbsoluteURL(), "WD_Filedownload", true);
			window.open();
		}
		catch(Exception e){ 
			wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
		 }

This code opens a new Internet Explorer, but not the image. When i printed the AbsoluteURL of the resource, its printing null. Where am i going wrong?

Thanks in advance,

Pravin

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Have you checked the content of the byte array before creating the resource? Does it contain the image data?

Armin

Former Member
0 Kudos

Hi Armin,

I am using this byte array code


 	private byte[] getByteArrayFromResourcePath(String resourcePath)throws FileNotFoundException, IOException 
	  {
		 FileInputStream in = new FileInputStream(new File(resourcePath));
		 ByteArrayOutputStream out = new ByteArrayOutputStream();
		 int length;
		 byte[] part = new byte[10 * 1024];
		 while ((length = in.read(part)) != -1) {
		   out.write(part, 0, length);
		 }
		 in.close();
		 return out.toByteArray();
	  }

Thanks

Pravin

Former Member
0 Kudos

Yes, ok, but did you verify (e.g. in the debugger) that the byte array indeed contains the image data after calling this method?

Armin

Former Member
0 Kudos

Pravin,

Try placing the image in src->mimes->Components->com.xxx.xxx.mycomponent folder.

Lemme know if that helps.

Regards,

Rajit

Former Member
0 Kudos

Hi,

Thanks for your reply. We will be having the image in the server and not in our development system. The code that we have used should work. Its working for document but not for images.

Any ideas.

Regards,

Pravin