Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

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

Was this useful?

66% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us