Hi all, I am working on a proxy function written i...
# cfml-general
t
Hi all, I am working on a proxy function written in cfml, all working fine as it can return the responses such as the text content & headers correctly back to the caller (also a CF app) My issue is when the destination URL is a binary file (such as ZIP). The caller app makes a cfhttp call to the proxy app asking it to make a cfhttp GET call to a ZIP file URL, and then the caller save the response content from the proxy as a zip file. The zip file saved by the caller is however not correct (cannot be unzipped and even is different in size, being larger than the zip file I requested) I've verified some of the obvious checks, such as • The content returned from the proxy, as seen from the caller cfhttp dump, is indeed binary, showing as Native Array (byte[]) • The proxy app returns the correct header application/zip
Here is the cfhttp dump of the direct (native) cfhttp call to the ZIP file URL from within the caller app vs the dump of cfhttp call to same ZIP file URL via the proxy app
w
if the proxy app saves the zip file to disk (before returning to the caller) is it corrupted or can it be opened normally?
t
yes, if the proxy save the content to zip, it is correct in size and can be unzipped
w
can you paste the code that calls the proxy and how it is returning the zip
you said 'if the proxy saves' above, does that mean you're NOT saving it before returning to the caller?
t
Correct, the proxy does not save the content, it just return whatever the cfhttp.filecontent it got back to the caller, by writeoutput function, perhaps the way the proxy return the binary content should be different to returning a text content?
w
it is, but cf abstracts a lot of that. i've never tried to chuck along one cfhttp's filecontent to another when it's binary, but might i suggest saving the proxy's zip to a ram:// file and then returning that via cfcontent
šŸ™Œ 1
t
ok, I can try that, thanks
hey, that works!
thank you!
āœ”ļø 1
I didn't save the content to zip or ram file in proxy, just directly return the cfhttp.filecontent back to the caller with cfcontent
w
i think you may be able to do that but it would require you to binary encode/decode before pushing it to the caller. just as easy to write to ram file, cfcontent push it back and allow cfcontent to delete the file
šŸ‘ 1
e
why not fake it? CURL or CFCURL pathtozip, then save the file as Something and redirect the browser to the file?