Support Article
Unabe to download the file from server path
SA-10870
Summary
User is unable to download a file and gets empty file from server path.
Pega uses
pega_rules_default.downloadFile(com.pega.pegarules.pub.util.StringUtils.concat(com.pega.pegarules.pub.util.StringUtils.ASIS, filePath, fileName), tools, bDeletefile); function to download the file.
Error Messages
Not Applicable.
Steps to Reproduce
Try to download a file from the server path.
Root Cause
User has configured a button where onclick calls an activity to download a file. On click of the button, the file is downloaded but the contents of the file are empty.
Resolution
Following is the local change for the java step of the activity:
/*The File Path along with the name to download need to be mentioned here */
String filePath = tools.getParamValue("FilePath");
java.io.FileInputStream fileInputStream=null;
java.io.File file = new java.io.File(filePath);
byte[] bFile = new byte[(int) file.length()];
try {
fileInputStream = new java.io.FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
}
catch(Exception e){
e.printStackTrace();
}
/* Change the name of the Test.docx to the actual file name that needs to be downloaded with extension.*/
String sErrorMessage = tools.sendFile(bFile, "Test.docx", false, null, true);
if (sErrorMessage != null){
tools.getThread().getThreadPage().putString("pyXMLStream", sErrorMessage);
}
Published June 30, 2015 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.