on 12-28-2008 12:34 PM
hi @,
I have used the File upload and Download UI elements as per the tutorial available. Now my requirement is to read the contents of the file and transfer it to the Backend system.
How can I achieve the desired fucntionality.
Thanks in advance,
Regards,
Amit
try this code to store image file in back end system.
IWDResource res=wdContext.currentMyDataElement().getPictureres();
InputStream in=res.read(false);
ByteArrayOutputStream bout=new ByteArrayOutputStream();
int length;
byte[] part=new byte[10*1024];
while((length=in.read(part))!=-1)
{
bout.write(part,0,length);
}
in.close();
pstmt.setBytes(8,bout.toByteArray());
If it is other than image file like word or text then try this in action
IWDResource resource = wdContext.currentResElement().getResorce(); // your existing handle to the upload resource type
try {
InputStream stream = resource.read(true);
byte b[]= new byte[1000];
stream.read(b);
String str = new String(b);
int i=str.length();
wdContext.currentContextElement().setOut(str);
wdContext.currentContextElement().setSize(i);
wdContext.currentResElement().setResourceurl(
wdContext.currentResElement().getResorce().getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The in back end field where u store the file should be byte array.
Regards,
H.V.Swathi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am not sure what kind of file you are reading - most probably a .csv or text file - in either case the following source code may help you.
String[24][24] numbers; //use an ArrayList here in case you dont know the number of columns or row.
File file = new File("something.csv"); //use the mimes path here
BufferedReader bufRdr = new BufferedReader(new FileReader(file));
String line = null;
int row = 0;
int col = 0;
//read each line of text file
while((line = bufRdr.readLine()) != null)
{
StringTokenizer st = new StringTokenizer(line,",");
while (st.hasMoreTokens())
{
//get next token and store it in the array
numbers[row][col] = st.nextToken();
col++;
}
row++;
}
//close the file
bufRdr.close();
The read contents will be stored in the ArrayList or the String Array. Use the contents of the array to call a BAPI (via Models) and insert the data into the backend system.
Hope that helps.
Thanks.
p256960.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.