We use the cf binaryencode function to convert a binary file to a base64 string that then is inserted into a coldfusion structure. Then we use the serizlizeJSON function to convert that structure to JSON.
When it fails we get this error:
JsonParsingError - Failed to decode VALUE_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character 'ﻘ' (code 0xfed8) in base64 content at [Source: java.io.StringReader@192fd063; line: 1, column: 12229]
Using the same code and the same file works correctly in CFMX 9.
We narrowed down to the serializeJSON function by manually creating the JSON string and bypassing the serializeJSON function completely.
Running CF11 Update 5 did not solve this either.
Anyone have any ideas on how to remedy this?
Sample code please.
<cffile action="readbinary" file="somefile.pdf" variable="objBinaryData" />
<cfset encodedFile = BinaryEncode(objBinaryData, "Base64")>
postOnbj = StructNew();
postOnbj["fileExtension"] = deSerData.fileExtension;
postOnbj["uploadedBy"] = deSerData.uploadedBy;
postOnbj["document"] = encodedFile;
d = SerializeJSON(postOnbj); //fails to serialize JSON
Not sure if it'll make any difference but the documentation for cffile readbinary says to use ToBase64(), not BinaryEncode(). I've never used BinaryEncode for anything but I have used ToBase64. If you end up with the same results, it sounds like a bug -- not unheard of. Maybe dump out the serialized JSON result and paste it into a JSON validator and see what is screwing up.
What if you use the full path, like this
<cffile action="readbinary" file="#expandPath('somefile.pdf')#" variable="objBinaryData" />
We are running into the same issues. We are storing user images into a database via binary. Our site is heavy on the jquery side and we use ajax calls to retrieve this data. Since json does not like binary, we have to convert the binary image into base64. We then make an ajax call and reference our cfc to return the data. When using returnformat=json, we have noticed that some of the base64 data was not encoded correctly. We did string compare and noticed changes in the string.....Ben Nadal has an article that discusses these nuances in more detail. Things like U+ gets converted to u//. Not sure why this has not been fixed. Seems like a simple solution from Adobe. I hope this helps....