cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload an document from desktop to an external URL

susmita_panigrahi
Active Participant
0 Kudos

Hi All,

There is a new requirement.There will be one browse button.Using this browse button user will search the document from the local machine and select the required document.Then there is 2nd button with name Upload.When user will click on this button the attached document will save in a External URL (IDM-User for document repository ).

Can anybody tell me how to implement this?

I have searched the forum ,there i found only option that is uploading the document to KM.KM is part of EP porta.So we can upload the document easily by implementing the blogs present in SDN.

However i didn't get any help file related to how to upload the document to exterval URL.

Thanks

Susmita

View Entire Topic
shabeer_skhan
Explorer
0 Kudos

Hi Susmita,

Hope the following procedure will help you with your requirement.

1. Place a FileUpload UI Element in the view of webdynpro application

2. Create a context value attribute of type 'Resource' (you can find this type under 'com.sap.ide.webdynpro.uielementdefinitions )

3. Bind the 'data' property and 'resource' property of the FileUpload UI element.

4. Place a button near the file upload and create an action for this button

5. Place this code in the action of the button



try{
BufferedInputStream bInput=new BufferedInputStream(wdContext.currentContextElement().get<AtrritbuteName>().read(true)); // Attribute Name is the name of 'Resource' type attribute bound to FileUpload element

URL targetUrl=new URL("<specify the url here>"); //URL is from java.net package
URLConnection urlConnection=targetUrl.openConnection();

BufferedOutputStream bOutput=new BufferedOutputStream(urlConnection.getOutputStream());

final int BUFFER=2048;
int count=0;
byte[] data=new byte[BUFFER];
while((count=bInput.read(data,0,BUFFER))!=-1){
	bOutput.write(data,0,count);
}//end while

}//end try
 catch (FileNotFoundException e) {
	// handle exception		
 } catch (MalformedURLException e) {
	// handle exception			
 } catch (IOException e) {
	// handle exception			
 }

remember to close all streams in a 'finally' block.

If it is a location in the disk of server that you want to upload the file, instead of using URL and URLConnection you can use the BufferedOutputStream as


BufferedOutputStream bOutput=new BufferedOutputStream(new FileOutputStream("<path of file>"));

Regards,

Shabeer.

susmita_panigrahi
Active Participant
0 Kudos

Hi Sabeer,

When i am trying to define the data type of context value attribute as Resource.I am not getting the option 'com.sap.ide.webdynpro.uielementdefinitions in my local NWDS.Also i am getting Data property of FileUploadUI element.There is no property with name Resource for the UI element.

Please let me now how i will proceed and what should be the type of context attribute which is bound to FileUploadUI element .

Thanks Susmita

Former Member
0 Kudos

Hi Shabeer,

I tried your code.

I need to upload a file to a directory on the server.

For instance ("C:/")

But I get the following error :- java.io.FileNotFoundException: C:\ (The system cannot find the path specified)

Is there anything I am missing ?

Thanks

Brian