Returning file pdf binary data in response body
search cancel

Returning file pdf binary data in response body

book

Article ID: 101361

calendar_today

Updated On:

Products

CA API Gateway

Issue/Introduction

The backend is returning the binary content of a file which is saved as a .pdf file. when called from the API Gateway.

The response can be seen with binary content in ${httpResponse1.parts.1} when returned as content-type=application/pdf (same as backend). The call is prompting to save as pdf but the file is only 9 bytes and not able to open.

When using a response body and return to template response as application/txt, Content-type=${httpResponse1.parts.1.contentType} Content-size=${httpResponse1.parts.1.size}, the returned response is Content-type=application/pdf Content-size=27240 which means the binary file content length is bigger.

When using a response body and return to template response as application/txt, ${httpResponse1.parts.1}, you can see the binary content on the response body %PDF-1.5 %���� 3 0 obj <>stream x���� .... startxref 26849 %%EOF

Environment

API Gateway 10.x, 11.x

Resolution

When using a return template response assertion, it is very important to specify the correct content-type. If you're forcing a multipart message (attachment with parts1) to be the main response, then specifying a content-type of application/pdf is required.