cancel
Showing results for 
Search instead for 
Did you mean: 

Upload/Download UI elements

Former Member
0 Kudos

Hi

Does anybody know if there's any documentation on upload/download applications.

i saw a general UI tutorial but it explained only how to design the iView and didn't explain the code behind.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

A brief but apt description on using FileDownload UI element is given below.

Insert the File Download UI element into the View.

The File Download UI element has various properties out of which only the data property is bindable and mandatory.

Bind this property to a context attribute of type binary.(Lets call the attribute filedata)

The file to be downloaded will be stored in this attribute.

The File Download element will be active only if there is data in the above attribute.

We have to write the file to be downloaded to the attribute.

Lets now look into the coding part how this can be achieved.

Consider that you have created a value attribute “filedata” of type binary in the context of the view. Also consider that the name of the file in server is “test.doc”.At this moment the attribute does not have any data.

try

{

File input = new File("C:
test.doc");

int length =(int)input.length();

//Create a byte array b to hold the file

byte b[] = new byte[length];

FileInputStream in = new FileInputStream(input);

//Reading the file to a byte array b

in.read(b);

in.close();

//Setting the data from the byte array to the context element.

wdContext.currentContextElement().setfiledata(b);

}

catch(Exception ex)

{

wdComponentAPI.getMessageManager().reportSuccess("Error in File

IO"+ex.toString());

}

// Structure information of the context attribute

IWDAttributeInfo attinfo = wdContext.getNodeInfo().getAttribute("filedata");

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attinfo.getModifiableSimpleType();

// Default File name which appears when opened on client machine

binaryType.setFileName("testing.doc");

//Explicitly setting the file type

binaryType.setMimeType(WDWebResourceType.DOC);

Kindly revert back if you find this useful. I can help you with the FileUpload functionality too.

Thanks and regards

Leena

Former Member
0 Kudos

Thanks that was very helpful

can you brief as well about the FileUpload functionality

Former Member
0 Kudos

Hi

Insert the FileUpload UI element into the View.Besides this, a button is also inserted in whose action we write the code for uploading (copying to server) data. Next, create a node, and within it, create two value attributes for binding to the ‘data’(of type 'binary') and ‘filename’(of 'string' type) properties of the FileUpload UIElement.

An action is created for the button. It is inside the method for this action that we will be writing the code for creating a file in the destination (server) and copying the contents from the source (where the file lies) to the file created in the server. This action is then bound to the ‘onAction’ property of the button.

In wdDoInit, create an element of the node and bind it to the node. After doing that, write the following code

IWDAttributeInfo attInfo = wdContext.node<<Node name>>().getNodeInfo().getAttribute("<<attribute bound to 'data' property>>");

ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();

IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;

In the onAction method for the button, specify the location where you want the file to be uploaded. On browsing, you get the file name in the value attribute assigned to the ‘filename’ property of FileUpload. Create a file by this name in the sever. The contents of the file is present in the value attribute bound to 'data' property in the form of binary data. This is written to the file created. This happens when you click the button. The code for this is given below.

try

{

String location = "<<location to where the file has to be uploaded>>"; //for eg: if you give it as 'C://', then the file is uploaded to the C drive of the server.

String file = wdContext.current<<Node>>Element().get<<attribute bound to 'filename' property>>();

String fileName = location +file;

File dest_file = new File(fileName);

FileOutputStream out = new FileOutputStream(dest_file);

if(element.get<<attribute bound to 'data' property>>() != null)

out.write(element.get<<attribute bound to 'data' property>>());

else

wdComponentAPI.getMessageManager().reportSuccess("The data is null");

out.close();

}

catch (FileNotFoundException e)

{

wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());

}

catch (IOException e)

{

wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());

}

Kindly reward points for the posts if you find them useful.

Thanks and regards

Leena

Former Member
0 Kudos

Hi Leena,

Thanks for your help. my problem is almost solved because of your your help.

However, when adding a "File upload element" it comes with an input field and a "browse button" i would like to put a breakopoint on the browse button( when pressing the browse button) but don't find in the code any action for clicking the browse button.

i ask you this because when i run the application through my IDE (eclipse) the application runs great and the file is uploaded to the destnation, however when i deploy on a Portal (Netweaver 2004s) the application doesnt work properly, after browsing through the files an clicking the upload button the application falls.

hope you can help me in that as well, and if not thank you very much for all your help up to now.

Matan

Former Member
0 Kudos

Hi

The functionality of 'Browse' button is pre-defined. It is just to browse your system in order to select the file that has to be uploaded.

Thanks

Leena

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

check this link

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/web dynpro sample applications and tutorials.htm

These tutorials will help for file upload and dowbnload

Regards,

RK

guru_subramanianb
Active Contributor
0 Kudos