• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

BLOB Images in and out of Oracle

Explorer ,
Mar 30, 2012 Mar 30, 2012

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:

  1. Pull the BLOB out of the database.
  2. Make it a CF image.
  3. Resize the image.
  4. Make the new image a BLOB.
  5. Put the new BLOB in the database.

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!

Views

2.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 30, 2012 Mar 30, 2012

Copy link to clipboard

Copied

Definitely use cfqueryparams in your update statement, solves so many issues with datatypes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 30, 2012 Mar 30, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 30, 2012 Mar 30, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 30, 2012 Mar 30, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 31, 2012 Mar 31, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2012 Mar 31, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 31, 2012 Mar 31, 2012

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2012 Mar 31, 2012

Copy link to clipboard

Copied

BKBK wrote:

... and not on a binary...

Please read "and not a binary".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 31, 2012 Mar 31, 2012

Copy link to clipboard

Copied

I'll try that the next time I'm working on it, thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 31, 2012 Mar 31, 2012

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==-

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 31, 2012 Mar 31, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 31, 2012 Mar 31, 2012

Copy link to clipboard

Copied

LATEST

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==-

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation