cancel
Showing results for 
Search instead for 
Did you mean: 

Download Image from Local PC

Former Member
0 Kudos

Hi,

I have a jpg image which is stored in the local system(not on the server).I have written an application from which I am not able to download the image from the local system.

I am using the following code but this code works only if the image is present on the server.



        String file = "C:\Folder_Name\image.jpg";
        final byte[] content = this.getByteArrayFromResourcePath(file);	
	final IWDCachedWebResource resource = WDWebResource.getWebResource(content, WDWebResourceType.UNKNOWN);
                try 
	{ 
	final IWDWindow window = wdComponentAPI.getWindowManager().createExternalWindow(resource.getURL(), "WD_Filedownload", true);
	window.open();
	}
	catch(Exception e)	{ 
	wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
	 }



         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();
	  }	 

And for downloading the file or image from local system I need to put the file in \src\mimes\Components folder; Where as I want the file to be downloadable anywhere from the local file system. Is that possible?

Thanks

Pravin

Accepted Solutions (1)

Accepted Solutions (1)

former_member1
Active Participant
0 Kudos

HI,

I am not able to get wat exactly you mean to say download from local system.

If you have image in local system, then you can upload the image in the server using file upload UI Element. And then you can use it.

For downloading the image to the local system use file download UI Element.

For further details please revert.

Thanks

Anish

Answers (2)

Answers (2)

Former Member
0 Kudos

Pravin,

If you want to display an image existing elsewhere on the local machine, you need to upload it first (use FileUpload UI component), store it in a byte array and then continue with your code below of creating a cached web resource.

And you place resources in src/mimes/component so that they will be available to the application (meaning for all users). This doesnt mean you are displaying the image from the local file system. When you deploy, these images go and live in the server and accessed from there.

In any case, the hardcoded image location in your code is valid only for YOU but not necessarily other user running the same application.

As such, you cannot access the client's file system explicitly (i.e local machine) due to security reasons. I know of no other way to do it with WebDynpro. Any resources must be present on the server side at some point of time. Either at application start or ask the user to provide it (like FileUpload).

No web technology allows that other than signed applets or trusted activex controls, as far as i know.

Hope that clears the confusion.

Thanks,

Rajit

Message was edited by:

Rajit Srinivas

Former Member
0 Kudos

Hi,

Use file upload/download component ....

Regards

Ayyapparaj

Former Member
0 Kudos

I have used but it's taking image file from src/mimes/component folder but I want it has to download from anywhere from the system.

Former Member
0 Kudos

Hi,

"I have a jpg image which is stored in the local system(not on the server).I have written an application from which I am not able to download the image from the local system."

What is your requirement? Why you want to download a file that is already existing on a system.

Regards

Ayyapparaj