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

PublicAPI sendFile Content-Type problem



Using the Pega PublicAPI sendFile(byte[] aFileData, java.lang.String aFileName, boolean aPersistFileToServiceExport, StringMap aHttpHeaders, boolean aSendForDownload) causes issues with the HTTP headers.

Setting Content-Type in the aHttpHeaders parameter always sends a response with Content-Type text/html;charset=UTF-8.

It appears that sendFile() does not handle the Content-Type setting correctly.

Error Messages

Not Applicable

Steps to Reproduce

Use the following code snippet:
byte[] byteArray=Base64Util.decodeToByteArray( base64String );

HashStringMap aMap = new HashStringMap();
aMap.put( "ContentDisposition", "inline;filename=\"aaa\"" );
aMap.put( "ContentType", "application/pdf" );

String sErrorMessage = tools.sendFile( byteArray, "aaa", false, aMap, false );

if( sErrorMessage != null )
    tools.getThread().getThreadPage().putString( "pyXMLStream", sErrorMessage );

View the generated output:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
X-dynaTrace-JS-Agent: true
Set-Cookie: Pega-RULES=H6AEC020E4FF52725F043638DA0055A91; Version=1; Comment="PegaRULES session tracking"; Path=/prweb
Content-Disposition: inline;filename="aaa"
ContentType: application/pdf
Cache-Control: max-age=0
Content-Encoding: gzip
Content-Type: text/html;charset=UTF-8
Content-Length: 23
Date: Fri, 19 Jun 2015 06:15:49 GMT

Obviously, there is a header ContentType but its value should be with the header Content-Type. For instance, it works as expected for the Content-Disposition header.

Root Cause

The root cause of this problem is in a third-party product. But first, the code does not recognize ContentType as a key in the aHttpHeaders map parameter for sendFile(); it has to be contentType (lowercase 'c').

Nevertheless, the Content-Type header will be set by the web container (in this case, Tomcat 7) based on the file name extension, regardless of what is set by PRPC. If the file has no extension, as in the code sample shown above, the default is text/html:charset=UTF-8.


As long as the file's extension is configured in Tomcat's web.xml, this should be sufficient to provide complete filenames (with an extension).

Published July 23, 2015 - Updated October 8, 2020

Was this useful?

0% 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