Skip navigation
Currently Being Moderated

BLOB Images in and out of Oracle

Mar 30, 2012 5:45 PM

Tags: #cfimage #blob #cf8 #imagegetblob

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!

 
Replies
  • Currently Being Moderated
    Mar 30, 2012 5:48 PM   in reply to Glowball

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 30, 2012 9:22 PM   in reply to Glowball

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 11:53 AM   in reply to Glowball

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 12:07 PM   in reply to Glowball

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 12:19 PM   in reply to BKBK

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 12:43 PM   in reply to BKBK

    BKBK wrote:

     

    ... and not on a binary...

    Please read "and not a binary".

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 2:38 PM   in reply to Glowball

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 31, 2012 3:01 PM   in reply to Glowball

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points