Download JPG’s with ColdFusion from a Linux server
July 7th, 2006 中文
I am working on a Flex and ColdFusion file upload/download component and came across the fun Linux and Windows file format issues. The files will upload correctly but if you try and pull down a JPG file form the linux server with ColdFusion's
-
<cffile action="read"
-
file="#folder#/#filename#" variable="fileData"/>
-
<cfcatch>
-
<cflog text="Invalid read #folder#/#filename#">
-
</cfcatch>
-
</cftry>
-
<cfif fileData NEQ ""><cfcontent reset="yes"><cfoutput>#fileData#</cfoutput></cfif>
For JPG's the code above will write the file as strange charactors and cause the JPG be unusable. You must set the "charset" attribute in the
-
<cffile action="read" charset="iso-8859-1"
-
file="#folder#/#filename#" variable="fileData"/>
-
<cfcatch>
-
<cflog text="Invalid read #folder#/#filename#">
-
</cfcatch>
-
</cftry>
-
<cfif fileData NEQ ""><cfcontent reset="yes"><cfoutput>#fileData#</cfoutput></cfif>
I assume it could even be another value depending on on the server's default values. So just beware of the charset value issues when downloading binary files with ColdFusion from linux servers.
Entry Filed under: ColdFusion MX 7




2 Comments Add your own
1. Cédric | 2006-07-17 at 9.48 am
Hello,
I’ve the same problem. When I upload a document (word, excel, …), the files seems to be uploaded correctly. But when I try to download it (using cffile tag), the file is corrupted (invalid charset I think).
Can you help me . Do you have found any solution ?
Thanks,
Ced
2. Renaun Erickson | 2006-07-17 at 9.52 am
<cffile action=”read” charset=”iso-8859-1″ …
Worked for me, here is a list of all the valid charsets try them all:
* utf-8
* iso-8859-1
* windows-1252
* us-ascii
* shift_jis
* iso-2022-jp
* euc-jp
* euc-kr
* big5
* euc-cn
* utf-16
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000250.htm
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed