Question

9
Replies
4758
Views
chaithanyas2395 Member since 2015 1 post
Marsh
Posted: 5 years ago
Last activity: 4 years 5 months ago
Closed
Solved

Issues with launching the excel file using tools.sendFile API

I am having issues with launching the excel file using tools.sendFile API. I am using the tools.sendFile(buffer, "compare.xls", false, null, true) to launch an excel file.

I have verified the buffer content and its completely alright. In the fiddler the content type is coming as application/octet-stream. In another scenario where I was able to launch excel from non-pega url, the content type is coming as application/vnd.ms-excel.

Is there an issue with the way, i am using the tools.sendFile API? I cant see any error in log or something like that, but the file is not launched, nothing happens.

Code below

/*Creating byte Array by reading excel file*/
java.io.File objFile = new java.io.File(tools.getParamValue("filedest"));

java.io.DataInputStream dis = null;
byte buffer [] = null;
try
{
dis = new java.io.DataInputStream(new java.io.FileInputStream(objFile));
buffer= new byte[dis.available()];
dis.readFully(buffer);
dis.close();
dis = null;
}
catch (Exception e)
{
throw new PRRuntimeException("Can't retrieve file attachment. Can't read File",e);
}

finally
{
if (dis != null) {
try {
dis.close();
} catch (Exception ex) {}
}
}
tools.putParamValue("length", buffer.length);
/*calling sendFile API of Pega*/
String sErrorMessage = tools.sendFile(buffer, "compare.xls", false, null, true);
if (sErrorMessage != null){
tools.getThread().getThreadPage().putString("pyXMLStream", sErrorMessage);
pega.terminateActivity();}

***Updated by moderator: Lochan to close post***
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Low-Code App Development
Moderation Team has archived post
Share this page LinkedIn