cancel
Showing results for 
Search instead for 
Did you mean: 

Upload a file on server

04-09-2007 11:02 PM
258 views 5 comments
0 Likes
SAP Managed Tags
Subscribe

Hi All

I am trying to upload the a file on to the server , using the following code

*******************

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("upload");

IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType) .getModifiableSimpleType();

String filename = binaryType.getFileName();

byte b[] = wdContext.currentContextElement().getUpload();

File path = new File("http://gge.mysap.pg.com:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/www/test.pdf");

try

{

FileOutputStream out = new FileOutputStream(path);

out.write(b);

out.flush();

out.close();

}

catch (FileNotFoundException e)

{

wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());

}

catch (IOException e)

{

wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());

}

*******************

the folder "www" does exist on the specified path.

I get the following message .

"http:/gge.mysap.pg.com:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/www/test.pdf (No such file or directory (errno:2)) "

Am I missing something...

0 Likes

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Likes

Hello Valery Silaev

I tried using the following code

/************************/

try

{

IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute("upload");

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

String filename = binaryType.getFileName();

URL u = new URL("http://gge.mysap.pg.com:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/www/"+ filename);

HttpURLConnection huc = (HttpURLConnection) u.openConnection();

huc.setRequestMethod("PUT");

huc.setDoOutput(true);

huc.setDoInput(true);

huc.connect();

OutputStream os = huc.getOutputStream();

byte b[] = wdContext.currentContextElement().getUpload();

os.write(b);

os.flush();

os.close();

huc.disconnect();

}

catch (IOException e)

{

wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());

}

/************************/

Now there is no error , but still the file is not created at the specified location .

Am I using the rght way to write the byte array ?

Regards,

Former Member
0 Likes

> Hi All

>

> I am trying to upload the a file on to the server ,

> using the following code

>

> *******************

> IWDAttributeInfo attInfo

> = wdContext.getNodeInfo().getAttribute("upload");

> IWDModifiableBinaryType binaryType

> =(IWDModifiableBinaryType)

> .getModifiableSimpleType();

>

> String filename = binaryType.getFileName();

>

> byte b[] =

> wdContext.currentContextElement().getUpload();

> File path = new

> File("http://gge.mysap.pg.com:50000/irj/servlet/prt/po

> rtal/prtroot/com.sap.km.cm.docs/www/test.pdf");

>

> try

> {

> FileOutputStream out = new

> t = new FileOutputStream(path);

> out.write(b);

> out.flush();

> out.close();

> }

>

> catch (FileNotFoundException e)

> {

> wdComponentAPI.getMessageManager().reportSuccess(e.g

> etMessage());

> }

> catch (IOException e)

> {

> wdComponentAPI.getMessageManager().reportSuccess(e.g

> etMessage());

> }

>

>

> *******************

> the folder "www" does exist on the specified path.

>

> I get the following message .

>

> "http:/gge.mysap.pg.com:50000/irj/servlet/prt/portal/p

> rtroot/com.sap.km.cm.docs/www/test.pdf (No such file

> or directory (errno:2)) "

>

> Am I missing something...

Hello Valery Silaev

Can you gimme an example regarding how can I use java.net.URL and java.net.HttpUrlConnection .

I am trying to upload a file residing on my desktop on to the server.

Regards,

Former Member
0 Likes

Ronnie,

java.io.File does not supports HTTP protocol (or any other protocol), you may access only local files that resides on same server.

Try to use java.net.URL and java.net.HttpUrlConnection to get binary content from URL.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

sid_sunny
Contributor
0 Likes

Hi Ronnie,

Just check whether this directory structure even exist on your server or not. The code you have pasted is correct but possibly the directory on server does not exist.

you can try this code with some other filepath like C:

Regards

Sid

Former Member
0 Likes

Hi Ronnie,

Follow this webblog - /people/rekha.malavathu2/blog/2006/12/12/handling-fileupload-and-filedownload-in-netweaver-developer-studionwds-2004s

It may be useful for you.

Thanks,

Raags