cancel
Showing results for 
Search instead for 
Did you mean: 

File Download

Former Member
0 Kudos

Hello everyone,

I'm using API JCIFS to access files in a remote server. Everything's fine and it lists correctly the content of the shared folder.

I have an object of type File as a result. How can i download it to my pc via webdynpro?

Other question: i read that performance would increase if i used IWDInputStream (i saw it here:

http://help.sap.com/saphelp_nw2004s/helpdata/en/42/fdf9c528d45171e10000000a1553f7/frameset.htm)

But i don't have type com.sap.tc.webdynpro.progmodel.api.IWDInputStream when i try browsing the java native types.

Am i missing some special package in my netweaver ?

thanks,

Nuno

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Dear Nuno Santos,

I facing same problem. If you have any solution Please update me. I already posted same as different question.

Former Member
0 Kudos

Hi,

refer this thread,

regards

karthik

Former Member
0 Kudos

Thank you for your fast answers

I allready did download a file with success. But now i'm having other problem. I'm using a table to list all files. One of the columns of the table is a FileDownload mapped to each binary type fileResource that i get by reading each file from server. I allready tested and all byte buffers are different. But when i try to download, it's always going for the last file in the table. Here's the code:

		SmbFile myfile = new SmbFile("smb://WORKGROUP;USER:pass@SERVER/SHARE/");
		SmbFile[] files = myfile.listFiles();
		for (int i = 0; i < files.length; i++){
			wdComponentAPI.getMessageManager().reportSuccess(i+" - "+files<i>.getCanonicalPath());
			IPrivateTesteView.IFicheirosElement elem = wdContext.createFicheirosElement();
			elem.setNome(files<i>.getName());
			elem.setTamanho(files<i>.getContentLength());
			elem.setPath(files<i>.getCanonicalPath());
			SmbFileInputStream fis = new SmbFileInputStream(files<i>);
			int size = (int)files<i>.length();
			byte[] buffer = new byte[size];
			int bytesread = fis.read(buffer);
			elem.setFileresource(buffer);
			IWDAttributeInfo attribinfo = wdContext.nodeFicheiros().getNodeInfo().
				getAttribute(elem.FILERESOURCE);
			IWDModifiableBinaryType binarytype =
				(IWDModifiableBinaryType) attribinfo.getModifiableSimpleType();
			binarytype.setFileName(files<i>.getName());
			StringTokenizer strtk = new StringTokenizer(files<i>.getName(),".");
			String ext = strtk.nextToken();
			ext = strtk.nextToken();
			if ("pdf".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.PDF);
			} else if ("doc".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.DOC);
			} else if ("ppt".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.PPT);
			} else if ("txt".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.TXT);
			} else if ("html".equalsIgnoreCase(ext) || "htm".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.HTML);
			} else if ("ps".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.PS);
			} else if ("rtf".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.RTF);
			} else if ("xls".equalsIgnoreCase(ext)){
				binarytype.setMimeType(WDWebResourceType.XLS);
			} else {
				binarytype.setMimeType(WDWebResourceType.UNKNOWN);
			}
			
			elem.setModifiablebinarytype(binarytype);
			wdContext.nodeFicheiros().addElement(elem);
			
			
		}
	} catch (SmbException e){
		wdComponentAPI.getMessageManager().reportWarning("Smbexception: "+e);
	} catch (MalformedURLException e){
		wdComponentAPI.getMessageManager().reportWarning("MalformedURLexception: "+e);
	} catch (UnknownHostException e){
		wdComponentAPI.getMessageManager().reportWarning("UnknownHostException: "+e);
	} catch (IOException e) {
		wdComponentAPI.getMessageManager().reportWarning("IOException: "+e);
	}

Can anyone tell me if i'm doing anything wrong?

CORRECTION - It's not going allways to the last file in the table, as i said. The application recognizes the binary fileResource of each file. The problem is in the popup to open or save. That's the one who is allways pointing to the last file. For example, my last file is a text file. If i open my first one (a pdf) it opens the file with the notepad instead of Adobe Reader, and the name of the file is the same as the text file.

Message was edited by: Nuno Santos

Former Member
0 Kudos

Hi,

in your code, you have written

StringTokenizer strtk = new StringTokenizer(files.getName(),".");

String ext = strtk.nextToken();

ext = strtk.nextToken();

i think here it may be the tokenizing problem.

try the following code instead of above,

StringTokenizer strtk = new StringTokenizer(files.getName(),".");

String ext = "";

while(strtk.hasMoreTokens())

{

ext = strtk.nextToken();

}

Former Member
0 Kudos

Hello Karthikeyan,

I can assure it's not because of that. I allready tried to print on screen the file extensions that are passed to modifiable binary type, and they're allright.

The problem is that if i try to print those values from node "Ficheiros" AFTER the "for" cycle (when i set them and add them to the node), it seems that it lost all info from first files and all elements appear with the same modifiable binary type from the last file of the node.

Former Member
0 Kudos

Hi Nuno,

Is your problem got solved? i am also having the same problem like you.

I am also getting only the last file that is there in my table. if you found any solution please share it with me.

Thanks in advance,

Meghana.

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Nuno,

<b>Release</b>: SAP NetWeaver 04 (not 04s!)

<b>Technical Problem</b>

The FileDownload UI Element does not work as a cell editor inside a table. The file download behavior is driven by the MIME type of the binary context attribute in the last table line node element.

<b>Technical Reason</b>

This problem is based on a technical restriction in SAP NetWeaver 04. To use a FileDownload UI element as a table cell editor all mime objects must have the same MIME type. This is based on the fact, that the MIME type information is stored on context attribute info level (one attribute info per node not per node element), so that the MIME type information is a singleton. This restriction is explained within my tutorial on <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/d2201c20-0801-0010-49b3-94fca8f590d5">uploading and Downloading Files</a>

<b>Solution A in NW04</b>

The first approach to solve this problem is the usage of non-singleton child nodes within the table's data node. Every non-singleton child node instance is associated with its node element (table line) an has its own attribute info or IWDModifiableBinaryType object. Store the file's binary data in an attribute of this non-singleton child node and populate every child node with a supply function. Based on the validate-by-rendering technique these non-singleton child nodes only get validated (this implies storing the binary data in the context attribute) when the related table lines get visible on the UI.

Read more detailed information on this topic within my answer in forum thread <a href="">Enhancing Web Dynpro Table Performance in NW 04 SP Stack13</a>

<b>Solution B in NW04</b>

Replace the FileDownload UI element with a LinkToURL UI element. Read this forum thread on to get more information on this workaround.

<b>Solution in NW04s: Downloading Files in a Table Using On-Demand Streams</b>

Use the new resource type introduced in NW04s to type a calculated context attribute storing the MIME object and stream it to the client on demand using the IWDInputStream API as the return type of a calculated context attribute getter. <u>I actually work on this new tutorial; it will be published on SDN in January 2007</u>.

Regards, Bertram

Former Member
0 Kudos

hi Nuno,

you are in the right direction...

Which version do you have? IWDInputStream is NW2004s, - since SP5, I guess.

If you use NW2004, there is a tutorial about file download and upload, you can find it here:

https://www.sdn.sap.com/irj/sdn/developerareas/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-d...

BTW: It's number 39.

Kind Regards

Stefanie