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 tag with the default charset it will not come down correctly.

XML:
  1. <cffile action="read"
  2.     file="#folder#/#filename#" variable="fileData"/>
  3.     <cfcatch>
  4.         <cflog text="Invalid read #folder#/#filename#">
  5.     </cfcatch>
  6. </cftry>
  7. <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 tag. Here is the code that worked for me:

XML:
  1. <cffile action="read" charset="iso-8859-1"
  2.     file="#folder#/#filename#" variable="fileData"/>
  3.     <cfcatch>
  4.         <cflog text="Invalid read #folder#/#filename#">
  5.     </cfcatch>
  6. </cftry>
  7. <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

Required

Required, hidden

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


Disclaimer: I work as a Flash/Flex Developer for Adobe Systems Incorporated. The opinions expressed here represent my own and not those of my employer.

My Amazon.com Wish List

Calendar

July 2006
S M T W T F S
« Jun   Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Most Recent Posts


Flex.org - The Directory for Flex