Details
Assignee
Michael OffnerMichael OffnerReporter
Joe WakefieldJoe Wakefield(Deactivated)Labels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
Affects versions
Priority
Major
Details
Details
Assignee
Michael Offner
Michael OffnerReporter
Joe Wakefield
Joe Wakefield(Deactivated)Labels
New Issue warning screen
Before you create a new Issue, please post to the mailing list first https://dev.lucee.org
Once the issue has been verified, one of the Lucee team will ask you to file an issue
Affects versions
Priority
Created 29 August 2018 at 18:33
Updated 4 February 2024 at 23:21
When downloading a file using Http(), Lucee downloads as text or byte array based on mimetype. I have a use case where I want to download various files and make them readable to the user, but javascript files are getting converted to a byte array. Both ACF and Lucee consider javascript as non-text, however ACF allows you to call result.fileContent.toString() to gracefully override the type. Using the same code in Lucee returns string representation of a byte array (e.g. "[B@44951b19").
From what I can tell, the root cause is that Lucee uses byte[] where as ACF uses java.io.ByteArrayOutputStream, and that class is what provides the desired toString() behaviour.
The workaround in Lucee is to manually create a java.lang.String and pass the byte[] to init().
Lucee's Http also has a "getasbinary" flag, but this can only be used to force binary download of text objects, not force text download of binary objects.
Solutions in order of preference:
Use a ByteArrayOutputStream instead of byte[] to store the fileContent variable, although I worry about it impacting other things (I've only glanced through the code).
Change getAsBinary behaviour so that setting "false" forces text-based download.
Add "application/javascript" to the HTTPUtil::isTextMimeType() check, although this would be creating another inconsistency between ACF and Lucee
Sample code:
<cfscript> local.http = new Http(url = "https://apis.google.com/js/api.js", method="GET"); local.result = local.http.send().getPrefix(); WriteDump(local.result); WriteDump(local.result.fileContent.toString()); // Lucee workaround -- fails in ACF WriteDump(CreateObject('java', 'java.lang.String').init(local.result.fileContent)); </cfscript>