Hi all, I'm using CF8 and storing images in Oracle as BLOB datatypes. I am not able to use CF to write files to the file server. I have about 50 large images already stored that need to have thumbnails made of them and stored in another field in each record. So, I need to do this:
The issue I'm having is that when an image starts out as a BLOB it doesn't seem to know the file type, so when I try to do step 5, above, I get "Verify your inputs. The source file should contain an extension,so that ColdFusion can determine the image format." It seems that if I start with an actual file in step 1 it works, but not if it's binary to start. This is my basic code edited for clarity.
<cfset thisImage = ImageNew(get.file_binary)>
<cfset ImageResize(thisImage, "500", "", "mediumQuality")>
<cfquery name="update" datasource="#dsn#">
UPDATE images
SET file_binary_thumbnail = #ImageGetBlob(thisImage)#
WHERE image_id = #get.image_id#
</cfquery>
Any idea how to get this to work? Thanks, everyone!
It seems that if I start with an actual file in step 1 it works, but not if it's binary to start.
Looks like that is a known issue. There is an undocumented work-around suggested in the comments here
ie Using imageObject.getImageBytes("jpg")
Though you should definitely use cfqueryparam in the actual query.
Thanks, cfSearching, that was a helpful link. It's always good to see I'm not the only one running into an issue. FYI, I've been a CF developer for eleven years and I wouldn't dare to use a query like I posted. But I wanted to get everyone's opinion on the image issue instead of having people focus on the mechanics of putting data into a database. I'm using cfqueryparam along with a ColdBox framework and it all works well, but it's not relative to this particular discussion. I wanted to simplify things by showing what I was doing in the most basic manner.
.. I wanted to simplify things by showing what I was doing in the most basic manner.
Yep, that makes complete sense. I always mention cfqueryparam when I do not know the background of the person asking the question. Feel free to note it was omitted for clarity next time, to stave off future "helpful" hints ;-)
-Leigh
Glowball wrote:
<cfset thisImage = ImageNew(get.file_binary)>
It could be that imageNew() expects an image as parameter, and not on a binary. What happens when you first convert from binary to image, like this?
<cfset imageAsBase64String = binaryEncode(get.file_binary, "base64")>
<cfset thisImage = imageReadBase64(imageAsBase64String)>
<cfset ImageResize(thisImage, "500", "", "mediumQuality")>
...
etc.
It could be that imageNew() expects an image as parameter, and not on a binary.
Actually it accepts several parameters, including "A BLOB from a database that contains image data."
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461 172e0811cbec22c24-796f.html
I just tried it and no change. Creating the image does not seem to be the problem. But rather how CF determines the image format when returning the bytes. From what I observed, it mistakenly uses file extension to determine the image type. Obviously that does not apply if the image was created from a byte array or bufferedImage. Sounds like a bug.
-Leigh
Message was edited by: -==cfSearching==-
North America
Europe, Middle East and Africa
Asia Pacific