cancel
Showing results for 
Search instead for 
Did you mean: 

Converting IWDResource to Array of Bytes

Amey-Mogare
Contributor
0 Kudos

Hi all,

I want to convert context attribute of type IWDResource into byte array. Any idea how to do this conversion?

Pls help.

Thanks and regards,

Amey Mogare

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

This is the code we have used to read the file whild uploading. Hope this helps.

IWDResource resource = element.getCtx_va_FileResource();
InputStream stream = resource.read(true);
String resourceName = resource.getResourceName();
String resourceExtn = resource.getResourceType().getFileExtension();

Here InputStream is - abstract class is the superclass of all classes representing an input stream of bytes.

Regars,

Charan

Amey-Mogare
Contributor
0 Kudos

Thank you for reply.

I just tried read method of InputStream and it worked..

Following is the code which I used to convert Resource to Byte Array


InputStream l_is_FileStream = wdContext.currentContextElement().getUploadedFile().read(false);
int l_int_NoOfBytes = l_is_FileStream.available();
byte[] byteArray = new byte[l_int_NoOfBytes];
int l_int_byteRead = l_is_FileStream.read(byteArray, 0, l_int_NoOfBytes);

This code populates byteArray[] with data of Resource.

Thanks and regards,

Amey Mogare

Answers (0)