Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to read the contents of the Uploaded file ?

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

Former Member
Former Member replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question