Skip to main content
Participant
September 24, 2008
Question

CF Base64 incompatibility to a Java Base64

  • September 24, 2008
  • 1 reply
  • 759 views
Hi,

When I download a binary file from an Oracle database with a CF MX7 web front-end (stored in field type CLOB), that was Base64 encoded by Apache's Java implementation of a Base64 encoder (see http://commons.apache.org/codec/api-release/index.html) via CF MX7's ToBinary function, the decoded file size is always slightly larger (e.g. 2365 bytes on a 3.91MB file). I'm aware that there are various RFC specifications for Base64 encoding. According to its reference manual, the CF MX 7 ToBase64 conforms to IETF RFC 2045, which is the same specification that the Apache Java Base64 implementation conforms to. I would be very grateful if someone could tell me why I'm seeing this discrepancy in file size as described above. Are the actual CF source code implementations of ToBase64 and ToBinary available to view? Do these functions adhere strictly to the RFC 2045 specification?

Please note. The standard Sun Java library doesn't include a Base64 class, hence the need for a third-party class. Also, I am aware that Adobe recommends the use of BinaryEncode and BinaryDecode for Base64 encoding/decoding in all new applications. However, I have to upload and download files via a legacy CF web front-end, which I cannot change, that uses the deprecated functions.

Many thanks for your help.

Nigel
This topic has been closed for replies.

1 reply

Inspiring
September 24, 2008
nbinns wrote:
> When I download a binary file from an Oracle database with a CF MX7 web
> front-end (stored in field type CLOB), that was Base64 encoded by Apache's Java
> implementation of a Base64 encoder (see
> http://commons.apache.org/codec/api-release/index.html) via CF MX7's ToBinary
> function, the decoded file size is always slightly larger (e.g. 2365 bytes on a
> 3.91MB file). I'm aware that there are various RFC specifications for Base64
> encoding. According to its reference manual, the CF MX 7 ToBase64 conforms to
> IETF RFC 2045, which is the same specification that the Apache Java Base64
> implementation conforms to. I would be very grateful if someone could tell me
> why I'm seeing this discrepancy in file size as described above.

You should look inside the files and check where the content differs. Is
the ToBase64() output of CF different from the Java output?

Jochem

--
Jochem van Dieten
Adobe Community Expert for ColdFusion
nbinnsAuthor
Participant
September 26, 2008
Hi,

Sorry about the delay in my response to your posting. The content of the two files is significantly different. I checked them with the 'Compare by Content' option in Total Commander. Some extra data seems to have been added to the end of the file downloaded file. One though I've had since my original posting: could the size of the byte[] array parameter passed to the Apache Base64 static method with signature encodeBase64(byte[] binaryData) be the cause of the problem? I set the value to 2048 (which is very similar to the 2365 bytes observed difference - the downloaded file is the larger of the two). May be I should set it to a smaller value? Does it matter that the output from the method isn't chunked? Unfortunately, I don't know enough about Base64 encoding to know which is the best method to use from this class and what static fields from this class to apply. Any advice would be gratefully received.

Many thanks.

Nigel