Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

file upload in webdynpro java

Hi, I have a reqirement where I have to upload the file ino server, and later user can down load the same from server.

i have seen file upload and down load example in SDN /docs/DOC-8061#15

but here they are just displaying the name and other details of the file that is trying upload but they are not really uploading the file in to the server. can any one guide me how to upload the file and where does the uploaded file resides in the server once it is succeefully uploded.

Regards,

Venki.

Former Member
Former Member replied

Hi Venki,

The following is the Procedure to DownLoad File from the Server Path.

1.) Take One Context Attribute named as "Texts" with Cardinality 0..n & Selection 0..1 & singleton = true .

2.) Take Two Context Attributes named " FileName " & " urlValue " of type String Under above Node "Texts".

3.) Bind Table UI Element & bind it's dataSource Property to the taken Context Node. Here it is "Texts".

4.) Insert One Column to The Table UI Element.

5.) Insert TableCellEditor( Take LinkToURL UI Element ).

6.) Bind " Texts.urlValue " to the references Property of the LinkToURL UI Element.

7.) Bind " Texts.FileName " to the text Property of the LinkToURL UI Element.

8.) All The UpLoaded Files in the Folder "FolderXYZ" are appeared as rows in the Table.

9.) Write the following code In the wdDoInit() Method of DownLoad View/After Upload Operation Performed.

int count=0;

WDWebResourceType obj=null;

File folder=null;

IWDMessageManager objMessageManager=wdComponentAPI.getMessageManager();

folder=new File("FolderXYZ"); // The Folder Name which we gave in the Upload Code.

File arr[]=folder.listFiles();

if(arr==null)

{

objMessageManager.reportWarning("No files exist in server.. Please Upload ");

return;

}

String str[]=new String(arr.length);
Put Array brackets as it is a Array.

String names[]=new String(arr.length);
Put Array brackets as it is a Array.

int c=0;

for(int k=0;k<arr.length;k++)

if(!(arr[k].isDirectory()))

c++;

int j=0;

for(int i=0;i<arr.length;i++)

{

try {

if(!arr<i>.isDirectory())

{

FileInputStream fis = new FileInputStream(arr<i>);

FileChannel fc = fis.getChannel();

byte[] data = new byte((int)(fc.size()));
Put Array brackets as it is a Array.

ByteBuffer bb = ByteBuffer.wrap(data);

fc.read(bb);

IWDCachedWebResource objCachedWebResource = null;

if (data != null)

{

String sr[]=arr<i>.getName().split("
.");

obj=new WDWebResourceType(sr[1],"html/"+sr[1],true);

objCachedWebResource = WDWebResource.getWebResource(data,obj);

objCachedWebResource.setResourceName(arr<i>.getName());

}

str[j]= objCachedWebResource.getAbsoluteURL();

names[j]=arr<i>.getName(); j++;

count++;

}

}catch(Exception e)

{

objMessageManager.reportException("Unable to get files from server "+e,false);

return;

}

}

ArrayList al=new ArrayList();

for(int k=0;k<count;k++)

{

IPrivateHeaderDisplayView.ITextsElement test=wdContext.createTextsElement();

test.setFileName(names[k]);

test.setUrlValue(str[k]);

al.add(test);

}

wdContext.nodeTexts().bind(al);

wdContext.currentContextElement().setVisibleCount(count);

With Regards,

Roop Kumar.

Edited by: Roop kumar Annavarapu on Sep 5, 2008 6:14 PM

Edited by: Roop kumar Annavarapu on Sep 5, 2008 6:16 PM

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question