cancel
Showing results for 
Search instead for 
Did you mean: 

How to Save a file uploaded in WebDynpro Java to Windows server

Former Member
0 Kudos

Hi Guys,

I need to save a file uploaded in WebDynpro Java to a location on one of my companys many internal Window servers but I cannot get it to work. I do not get any errors with the following code, but NOTHING happens... And when I check the folder it is still emply... Please advise. I am particularly not sure about specifying the Path syntax. Also, I do have permission to write to this server. Is it even possible to save to a Windows server from WebDynpro??

//uploaded document already in context...

byte[] file = element.getFileResource();

// get the size of the uploaded file

element.setFileSize(this.getFileSize(file));

wdContext.currentContextElement().setFSize(this.getFSize(file));

// get the extension of the uploaded file

element.setFileExtension(binaryType.getMimeType().getFileExtension());

String fName = wdContext.currentContextElement().getFName();

String fExt = wdContext.currentContextElement().getFileExtension();

String foName1 = "
server01.w9\Files\P
HRP_Attachments\" + fName + ".pdf";

File f1 = new File(foName1);

DataOutputStream dos1;

dos1 = new DataOutputStream(new FileOutputStream(f1));

dos1.write(file);

dos1.flush();

dos1.close();

Edited by: christiaanp on Sep 30, 2011 8:07 AM

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

Hi Christiaan,

When specifying the path, make sure you escape the slashes

So, when you would normally use something like

\\server\path\file.txt

in your code you must use it in the form:

String fileName = "\\\\server\\path\\file.txt";

Hope this helps!

Robin van het Hof

Former Member
0 Kudos

Hi there!

Thank you so much - but I have in fact tried this as well.

C

Qualiture
Active Contributor
0 Kudos

Hi,

In retrospect, it's better to use it in following form btw:

String filename = File.seperator + File.seperator + "server" + File.seperator + "path"+ File.seperator + "filename.txt";

to be platform independent, but then I don't think it would solve your issue...

Can you check permissions? The service user under which the NetWeaver application runs (so not the logged in NW user) should have permissions to write to your destination

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

the file object cannot handle your case

i would suggest you setup ftp server in target server and upload the file using ftp java api, you can use some open source solution.

Qualiture
Active Contributor
0 Kudos

IMO, since the File object can handle UNC pathnames, as long as the shared server is accessible to the NetWeaver server and with proper permissions, it should be perfectly possible to write to this destination