Coldfusion CFIMAGE problem - getting an error when trying to read an image URL that has a space in the filename

Posted on 2009-04-20
Last Modified: 2012-05-06
I'm using the CFIMAGE tag (under ColdFusion 8) to retrieve the dimensions of an image that's hosted on another website (via an absolute url):

<cfimage action="info" structname="imagesize" source="">

However, ..  the value of the "thumbnail" variable will sometimes be a filename that contains a space in it, ... and whenever that happens, I get the following error message:

An exception occurred while trying to read the image. Server returned HTTP response code: 400 for URL: of a state florida.JPG

How can I get around this problem?  The source attribute for CFIMAGE has to be a URL in this case (it can't be an absolute or relative path) -- and changing the 1000+ image filenames isn't an option. Please advise.

Thanks in advance,
- Yvan

Question by:egoselfaxis
    LVL 16

    Accepted Solution

    Changes spaces to %20 or use URLEncodedFormat()

    <cfimage action="info" structname="imagesize" source=", " ", "%20", "ALL")#">

    <cfimage action="info" structname="imagesize" source="">

    Author Comment

    Hmm, .. I thought I'd tried that, but I guess I must have messed it up somehow.  Your method worked using (the replace method).  Thanks!

    - yg


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
    This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now