on 04-09-2007 10:02 PM
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...
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.