cancel
Showing results for 
Search instead for 
Did you mean: 

Upload / Save file via FileUpload UI Element under predefined path

Former Member
0 Kudos

Hi,

I am pretty new to this topic and need some help.

I need a Web Dynpro App where I can select a file via FileUpload UI Element and save this file to a predefined path e.g. to a server. I already found [this help|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71?quicklink=index&overridelayout=true] but in this example the file is stored at the SAP Server!

How can I achieve this? May you give me a sample code?

I appreciate your help.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Martni,

If you are trying to store a file into a folder in WAS(Web Application Server) here is the code snippet. It worked for me, so you can try it and let me know if it works for you or not.

try{

File fp = new File(relativePath+ fileName);

fp.createNewFile();

FileOutputStream fos = new FileOutputStream(fp);

BufferedOutputStream bos = new BufferedOutputStream(fos);

InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false);

int l_int_NoOfBytes = l_is_FileStream.available();

byte[] byteArray = new byte[l_int_NoOfBytes];

l_is_FileStream.read(byteArray, 0, l_int_NoOfBytes);

bos.write(byteArray);

bos.flush();

}

catch (Exception e) {

wdComponentAPI.getMessageManager().reportException("Cannot save the file: "+fileName);

}

Former Member
0 Kudos

Hi Martni, Above answer was incomplete

try{					
	File fp = new File(relativePath+ fileName);
	fp.createNewFile();
	FileOutputStream fos = new FileOutputStream(fp);
	BufferedOutputStream bos = new BufferedOutputStream(fos);
	InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false);
	int l_int_NoOfBytes = l_is_FileStream.available();
	byte[] byteArray = new byte[l_int_NoOfBytes];
	l_is_FileStream.read(byteArray, 0, l_int_NoOfBytes);
	bos.write(byteArray);
	bos.flush();
					
}
catch (Exception e) {
	wdComponentAPI.getMessageManager().reportException("Cannot save the file: "+fileName);
}

In the above snippet "relativePath" is the path to the folder in WAS and "filename" is the name of the file along with its extn Ex. test.doc, or image.jpg

InputStream l_is_FileStream = elAttachmentsElement.getVa_Resource().read(false)

The above line of code is the sixth line in the snippet and here "elAttachmentsElement" is the element of the node having "Va_Resource" context attribute, which is bound to FileUpload UI element.

Regards,

Vishweshwara P.K.M

Edited by: Vishweshwara P.K.M on Jun 28, 2010 1:31 PM

Former Member
0 Kudos

Hi, thank you very much for your response. That also works for me. Regards

Former Member
0 Kudos

Hi Visweswarayya,

I am also doing the same upload file.but I want to save the file in one of my drive path .

for example I want to save the file in " D " drive of my mechine.I have given the path as " D:\XYZ folder name.but the the colun : is not getting accepted after the drive name.

as far as I know the path should be D:\XYZ folder name.

is the path should be given in any other way apart from this?

appriciate your help.

Raji

Former Member
0 Kudos

Hi,

I set the path like this way and it works:

String relativePath = "C:\\_TMP\\";

May you try?

Answers (0)