Question

9
Replies
5132
Views
chaithanya siddanthi (chaithanyas2395)
Marsh

Marsh
US
chaithanyas2395 Member since 2015 1 post
Marsh
Posted: June 29, 2015
Last activity: July 18, 2017
Posted: 29 Jun 2015 12:06 EDT
Last activity: 18 Jul 2017 10:50 EDT
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);

}

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, This thread is closed to future replies. Content and links will no longer be updated. If you have the same/similar Question, please write a new Question.