cancel
Showing results for 
Search instead for 
Did you mean: 

File download problem

former_member187702
Active Participant
0 Kudos

Hi

I am working on a file download application..I am using this code

try {

String resourcePath = WDURLGenerator.getResourcePathwdComponentAPI.getDeployableObjectPart(),ResultView.FILE_NAME);

wdContext.currentContextElement().setCtx_FileResource(this.getByteArrayFromResourcePath(resourcePath));

binaryType.setFileName(ResultView.FILE_NAME);

binaryType.setMimeType(WDWebResourceType.JPG_IMAGE);

}

catch (WDAliasResolvingException e) {

wdComponentAPI.getMessageManager().reportException(

e.getLocalizedMessage(),

true);

} catch (Exception e) {

throw new WDRuntimeException(e);

}

My view name is "ResultView" and context name is ctx_FileResource.

I have to download a file from the server..

I have to download a properties file from the server..

I am getting error in this line.

<b>wdContext.currentContextElement().setCtx_FileResource(this.getByteArrayFromResourcePath(resourcePath));</b>

The error is Method getByteArrayFromResourcePath is not defined for the view..

Can anybody help on this.

Thanks

Shilpa

Accepted Solutions (0)

Answers (1)

Answers (1)

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

Write the getByteArrayFromResourcePath() method in

//@@begin others

private byte[] getByteArrayFromResourcePath(String resourcePath)

throws FileNotFoundException, IOException {

FileInputStream in = new FileInputStream(new File(resourcePath));

ByteArrayOutputStream out = new ByteArrayOutputStream();

int len;

byte[] part = new byte[10 * 1024];

while ((len = in.read(part)) != -1) {

out.write(part, 0, len);

}

in.close();

return out.toByteArray();

}

// store image file name in constant FILE_NAME

IWDModifiableBinaryType binaryType ;

//@@end