Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Definitely use cfqueryparams in your update statement, solves so many issues with datatypes.
Copy link to clipboard
Copied
I edited the code for clarity, it actually looks quite different than that. I cut out all of the excess so it would be easier to focus on what I was trying to do.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
.. 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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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/WSc3ff6d0ea77859461172e0811cbec22c24-796f.html
Copy link to clipboard
Copied
BKBK wrote:
... and not on a binary...
Please read "and not a binary".
Copy link to clipboard
Copied
I'll try that the next time I'm working on it, thanks!
Copy link to clipboard
Copied
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==-
Copy link to clipboard
Copied
Hey, thanks for checking that out for me, I appreciate it. It's always good to hear when someone else is seeing the same weirdness.
Copy link to clipboard
Copied
It's always good to hear when someone else is seeing the same weirdness.
No problem. A second (or third) set of eyes makes a great sanity check.
Message was edited by: -==cfSearching==-