• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 872
  • Last Modified:

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

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="http://www.thebookco.com/images/Books/#thumbnail#">

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.
java.io.IOException: Server returned HTTP response code: 400 for URL: http://www.thebookco.com/images/Books/portrait 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

1 Solution
Changes spaces to %20 or use URLEncodedFormat()

<cfimage action="info" structname="imagesize" source="http://www.thebookco.com/images/Books/#Replace(thumbnail, " ", "%20", "ALL")#">

<cfimage action="info" structname="imagesize" source="http://www.thebookco.com/images/Books/#URLEncodedFormat(thumbnail)#">
egoselfaxisAuthor Commented:
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


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now