cancel
Showing results for 
Search instead for 
Did you mean: 

How to Upload a File Client to a Server

Former Member
0 Kudos

Hi

I am Trying to Upoad a File From Client to Server.

For this i am using FileUpload UI element in the WebDynpro.

I want to know the process.Please send the Process

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

What do you mean by process?

Usage of FileUploadUI control:

1. create a FileUploadUI element in your layout

2. create a context value attribute of type binary

3. make the binary attribute modifiable (in wdInit of the view controller)

4. create a button to trigger the upload from the ui

Former Member
0 Kudos

i copied this code in init method iam getting error at binaryType at second line what i have to do

IWDAttributeInfo attInfo = wdContext.nodeRoot().getNodeInfo().getAttribute("FileUpload");

//binaryType = (IWDModifiableBinaryType) attInfo.getModifiableSimpleType();

Former Member
0 Kudos

wdContext.getNodeInfo().getAttribute(IPrivate<YOUR_VIEW>.IContextElement.<YOUR_BINARY_VALUE_ATTRIBUTE>).getModifiableSimpleType();
Former Member
0 Kudos

> IWDAttributeInfo attInfo =

> wdContext.nodeRoot().getNodeInfo().getAttribute("FileU

> pload");

>

> //binaryType = (IWDModifiableBinaryType)

> attInfo.getModifiableSimpleType();

you get a classcastexception, right? Replace IWDModifiableBinaryType with ISimpleTypeModifiable in your second statement.

For context access better use the automatically generated static constants instead of hardcoded strings.

Former Member
0 Kudos

hi,

I am trying retrive the file path from the UIElement "File upload". I tried many ways but all were unsuccessful. Do you have any idea how to get the file path from the UI Element?

regards

Praveen

Answers (1)

Answers (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Somaraja,

For doing so just follow these steps:

<i>1) Create a attribute in the context of your view of type <u>Resource</u> (This will hold the value of the file you have selected) from your local System.

2) After that create a button with a action of say onUpload.

3) In code implementation of this onUpload function get the insatance of this resource object and get the value of the resouce in inputstream.

4) Put this inputStream object in a file and that will be uploaded at the server side.</i>

I am also attaching a code snippet for your better understanding.

			 
IPrivateFirst.IUploadFileElement element = wdContext.currentUploadFileElement();

InputStream text=null;
	int temp=0;  	
	
    try {
		//	If a file in the FileUpload field exists
    	File file = new File(element.getFileName().getResourceName());
		FileOutputStream out = new FileOutputStream(file);
		
    	if (element.getFileName() != null) {

    		text = element.getFileName().read(false);
			 while((temp=text.read())!=-1)
			 {
			 out.write(temp);
			 }

		}
    	out.flush();
    	out.close();
	} 
    
    catch (IOException e2) 
	{
    	e2.printStackTrace();
	}

I hope this will solve the problem. Actually the error you are getting is because of the filetype you have selected. The Upload UI Element accepts the Resource as its Element type.

If any other information required then please let me know.

Regards

Pravesh

PS: Please consider rewarding points if helpful and solved.