on 06-14-2007 1:18 PM
Hi All
I am working on Netweaver2004s
The scenario is like
I have a webdynpro application where in I need to Upload , Display the image in browser and then FTP the image to a server .
I have created a FileUpload type UI and bound it to binary type attribute say Datasource.
Now
<b>byte[] imgData = wdContext.currentContextElement().getDatasource();</b>
gives byte[] and this imgData I have been using in my FTP code.
1) Now please let me know since IWDModifiableBinaryType APIs has been replaced by <b>IWDResource</b> and <b>WDResourceFactory</b>, How can i proceed with getting the byte Array ?
2) I have an Image UI, I have been using <b>IWDCachedWebResource</b>, to convert the URLString to Image.
<b>IWDCachedWebResource res =
WDWebResource.getWebResource(
imgData,
WDWebResourceType.JPG_IMAGE);</b>
Now using <b>res.getAbsoluteURL(),</b> i am getting the string which i have bound to Image UI.
Now IWDCachedWebResource has also deprecated.
Can u pls help in my scenario, how can i replace IWDModifiableBinaryType and IWDCachedWebResource with IWDResource APIs.
Regards
Sonal Mangla
Hi ,
For upload use this code:
InputStream text = null;
int temp = 0;
try
{
File file = new File(wdContext.currentContextElement().getFileResources().getResourceName());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getFileResources()!=null)
{
text = wdContext.currentContextElement().getFileResources().read(false);
while((temp=text.read())!=-1)
{
op.write(temp);
}
}
op.flush();
op.close();
String path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess("File has uploaded Sucessfully:\n"+path);
}
catch(Exception e)
{
e.printStackTrace();
}
For Download:
/*********************************For Downloading PDF**********************************************/
it should be in wdDoInit().
String fname = wdContext.currentEx_Project_Search_ResultsElement().getProjectid().toString();
String FILE_NAME =fname+ ".pdf";
WDWebResourceType FILE_EXT = WDWebResourceType.PDF;
try {
String resourcePath = "E:/usr/sap/CR5/DVEBMGS01/j2ee/cluster/server0/" + FILE_NAME;
//wdComponentAPI.getMessageManager().reportSuccess(resourcePath);
IWDResource resource = WDResourceFactory.createResource( new FileInputStream(new File(resourcePath)),FILE_NAME,FILE_EXT,true);
wdContext.currentContextElement().setFileResource(resource);
}
catch(Exception e)
{
e.printStackTrace();
}
<b></b><i></i><u></u>Place this code in end of the view implementation, it should be between begin and end statements:
private byte[] getByteArrayFromResourcePath(String resourcePath)
throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10 * 1024];
while ((length = in.read(part)) != -1) {
out.write(part, 0, length);
}
in.close();
return out.toByteArray();
}
<b></b><b></b><b></b><i></i><b></b><b></b><i></i><u></u>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sonal,
Here is the code for byte array.
String resourcePath =
WDURLGenerator.getResourcePath(
wdComponentAPI.getDeployableObjectPart(),
FileDownloadView.FILE_NAME);
// retrieve byte array for given resource path and store it
// in context value attribute 'FileResource'
wdContext.currentContextElement().setFileResource(
this.getByteArrayFromResourcePath(resourcePath));
//--
/**
Returns a byte array for a given file resource path
*/
private byte[] getByteArrayFromResourcePath(String resourcePath)
throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10 * 1024];
while ((length = in.read(part)) != -1) {
out.write(part, 0, length);
}
in.close();
return out.toByteArray();
}
//----
// store image file name in constant FILE_NAME
private static final String FILE_NAME = "sap.jpg";
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/202a850a-58e0-2910-eeb3-bfc3e081257f">Uploading and Downloading Files in Web Dynpro Java</a>
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/00062266-3aa9-2910-d485-f1088c3a4d71">Uploading and Downloading Images in Web Dynpro Java</a>
Regards,
Mithu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mangla,
For downloading use this
Create a context attribute and set calculated as true then u will get a getter method,In that u write code like this
IWDInputStream stream = null;
try {
stream = WDResourceFactory.createInputStream(new FileInputStream(new File(<give the location of a file u want to download>));
}
catch (Exception e)
{
e.printStackTrace();
}
return stream;
for open file u set "resource"as Resource type context attribute
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sathish
Thanks for the effort. I gor the Stream, But how can i convert it to byte array.
Either we have to create InputStream
<b>InputStream imgDataInp =
wdContext.currentContextElement().getDatasource().read(true);
byte[] imgData = new byte[imgDataInp.available()];</b>
But its not working
and what is to be done 2nd point mentioned
Regards
Sonal Mangla
Hi Sonal,
as you are working on NW70, you should check out Bertram Ganz' Weblogs about FileUpload and FileDownload in WebDynpro where he explains hot to use the WDResource classes in detail.
/people/bertram.ganz/blog/2007/05/25/new-web-dynpro-java-tutorials--uploading-and-downloading-files-in-sap-netweaver-70
Here is the corresponding tutorial
and sample project:
Regarding the image: I usually place them in the project under "src/mimes/Components/<package>".
Next create a value attribute and put the filename of the image in there. That one you have to use as a "source" attribute in your ImageUI. That should work.
Best regards,
ok
Message was edited by:
Oliver Kohl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mangla,
For uploading use this code
try{
String Upload=wdContext.currentContextElement().getResource().getResourceName();
FileOutputStream fout=new FileOutputStream(new File(upload));
}
catch(Exception e)
{
e.getStackTrace();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.