Answered
Output Binary data to browser as file
I know this has been covered a thousand time, but every
example I am given does not work.
I am accessing a Java WebService to get a document (in this case PDF). This WS has no WDSL, so I am hitting it through CFHTTP. The WS returns me a hashmap with error codes etc. One element is a Binary string.
I have done everything imaginable and the most I can do is get the raw text to display. Unfortunately, saving a temp file then using CFFILE is not an option for security reasons; however, if I try this the file is corrupted and will not open. When I use CFHEADER I get a complaint about java.lang.String. However, ToBinary gives me a CF error with garbage text and no real error, and BinaryDecode always whines about input and output encodings not matching.
This is what I use the call the service:
<CFHTTP URL="HIDDEN" METHOD="GET" RESULT="testFN" CHARSET="ISO-8859-1"></CFHTTP>
And these are somethings I have tried:
<cfheader name="Content-Type" value="pdf">
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=my.pdf">
<CFCONTENT TYPE="application/pdf" VARIABLE="#BinaryDecode(testFN.Filecontent, "Base64")#">
<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
out = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(arrayLen(testFN.Filecontent));
out.write(testFN.Filecontent);
out.flush();
out.close();
</cfscript>
<cfcontent type="application/pdf; charset=ISO-8859-1">
<CFSCRIPT>
writeOutput(toString(testFN.Filecontent));
</cfscript>
None work. I either get a blank page, a CF error, or plain text. Other Java application use this same WS without issue, so any complaints about the WS have been ignored.
I need help badly. I am not sure what else to try.
I am accessing a Java WebService to get a document (in this case PDF). This WS has no WDSL, so I am hitting it through CFHTTP. The WS returns me a hashmap with error codes etc. One element is a Binary string.
I have done everything imaginable and the most I can do is get the raw text to display. Unfortunately, saving a temp file then using CFFILE is not an option for security reasons; however, if I try this the file is corrupted and will not open. When I use CFHEADER I get a complaint about java.lang.String. However, ToBinary gives me a CF error with garbage text and no real error, and BinaryDecode always whines about input and output encodings not matching.
This is what I use the call the service:
<CFHTTP URL="HIDDEN" METHOD="GET" RESULT="testFN" CHARSET="ISO-8859-1"></CFHTTP>
And these are somethings I have tried:
<cfheader name="Content-Type" value="pdf">
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=my.pdf">
<CFCONTENT TYPE="application/pdf" VARIABLE="#BinaryDecode(testFN.Filecontent, "Base64")#">
<cfscript>
context = getPageContext();
context.setFlushOutput(false);
response = context.getResponse().getResponse();
out = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(arrayLen(testFN.Filecontent));
out.write(testFN.Filecontent);
out.flush();
out.close();
</cfscript>
<cfcontent type="application/pdf; charset=ISO-8859-1">
<CFSCRIPT>
writeOutput(toString(testFN.Filecontent));
</cfscript>
None work. I either get a blank page, a CF error, or plain text. Other Java application use this same WS without issue, so any complaints about the WS have been ignored.
I need help badly. I am not sure what else to try.
