Reading A Remote File With CFHTTP Using Railo And ColdFusion

Published: {ts '2012-08-28 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/reading-a-remote-file-with-cfhttp-using-railo-and-coldfusion/

One of the new features I rolled last week on my site is an embedded QR code in the print layout. To do this I use cfhttp to pull the corresponding qr code image file of some shortened url from the bitly service. I then either store it in the database for later retrieval or output it directly to the browser.

However when I deployed this feature to my server I encountered a small incompatibility between the way Railo and Adobe ColdFusion use cfhttp to return a bytearray.

Using CFHTTP To Read A Remote File Binary With ColdFusion

Here is the code I used to accomplish this on my local machine which runs Adobe ColdFusion.

Note how on the second line I call toByteArray() on the filecontent value. This is necessary because as I understand it in ACF "fileContent" contains a ByteArrayOutputStream Object.

Using CFHTTP To Read A Remote File Binary With Railo

When I deployed this code from my developer machine running Adobe ColdFusion to my server which runs Railo I got this error on trying to call the toByteArray() method.

No matching Method/Function for fileContent.toByteArray() found

After a little searching around I discovered that in Railo there is no toByteArray() method because it simply is not needed. The filecontent variable is already a true byte array so all I had to do was drop the toByteArray() call.

Its a small but significant difference.