Calendar

December 2008
S M T W T F S
« Nov   Jan »
 123456
78910111213
14151617181920
21222324252627
28293031  

Tag Cloud

Categories

Archives

Recent Posts

Recent Comments


« Merry Christmas! | Main | Happy New Year 2009! »

BLOB from Java to Flex via BlazeDS

By Rich Tretola | December 31, 2008
5,008 views

I was recently tasked with the job of loading images into a Flex app that were being stored within an Oracle database under data type Blob.

It turns out that this is pretty simple to do. The following is a simplified example as my original involved some complex objects and Hibernate:

After selecting the field from the database and storing it to the variable imageBlob, I simply converted it to a byte array using the getBytes() method and then and store it in the variable imageBA .

Java:

1
2
Blob imageBlob = //  image data returned from Database as Blob
byte[] imageBA = imageBlob.getBytes(1, (int) imageBlob.length());

On the Flex side I simply bind the imageBA to the image source.

Flex

1
<mx:Image source="{imageBA}" />

Topics: BlazeDS, Flex | 16 Comments »

16 Responses to “BLOB from Java to Flex via BlazeDS”

  1. Teodor Baciu Says:
    December 31st, 2008 at 5:12 pm

    Why didn’t you just send the byte array directly through BlazeDS ?

    Reply to this comment

    Rich Tretola Reply:

    I had a typo in my original code when I tried that so I assumed there was something more devious at work within my AMF connection. My mistake, I found the typo and now all is fine simply passing the byte[]. I have updated the entry.

    Reply to this comment

  2. anonimus Says:
    January 21st, 2009 at 2:56 pm

    are you shure that works?? what is the type of de imageBA in de flex side? you are using RemoteObject? can anyone put some sample of passing images from java to flex via BlazeDS? thanks

    Reply to this comment

  3. Rich Tretola Says:
    February 5th, 2009 at 12:19 pm

    Just be sure that your Java side datatype is byte[]; and your ActionScript side datatype is flash.utils.ByteArray; and you then can simply bind that value to the source property of an Image component.

    Reply to this comment

  4. Rich Tretola Says:
    February 5th, 2009 at 5:24 pm

    You are using an ItemRenderer within the grid? I am confused by what you are trying to do. I suggest you try binding your byte array to an Image component outside of the datagrid first.

    Reply to this comment

  5. Rich Tretola Says:
    February 5th, 2009 at 6:11 pm

    Not sure what you mean by customized Java classes. You simply need to convert it to a byte array as in my sample code above. It sounds like there may be two issues.

    1) make sure when you receive the data within Flex it is actually a byte array

    2) Make sure you are using your ItemRenderer properly any binding to the correct property.

    If you are still having problems, let me know and I’ll try to help you further through email.

    Reply to this comment

  6. pibe Says:
    February 5th, 2009 at 6:23 pm

    i receive the data as a byte array

    and ItemRenderer is used properly, actually i have test it with a Image on my local disk.

    would you like to see my code? it is not so big because is just a small prototipe.

    Thnks so much!

    Reply to this comment

    ragin Reply:

    Please share the code

    Reply to this comment

  7. Rich Tretola Says:
    February 5th, 2009 at 7:44 pm

    I sent you an email, please reply with your code sample.

    Reply to this comment

    ragin Reply:

    please share the source.

    Reply to this comment

  8. Tom Says:
    March 13th, 2009 at 4:57 pm

    I’m also sending an array of bytes from Java to Flex.
    I have a tilelist which renders thumbnails. In my Thumbnail class I have the following code, where data.cover points to the byte array.

    But instead of an image it shows a red cross.. Do you know what the problem is here?

    Reply to this comment

  9. Tonyzheng Says:
    March 16th, 2009 at 4:46 am

    Who can give me a copy of the source code . thanks a lot.

    Reply to this comment

  10. Tonyzheng Says:
    March 16th, 2009 at 4:46 am

    Who can send the source code . thanks a lot

    Reply to this comment

    Rich Tretola Reply:

    There is no additional source code. Everything is in the original post. Just those 3 lines!

    Reply to this comment

  11. Gerson Says:
    August 3rd, 2009 at 11:56 am

    Useful tip,, Thanks

    Reply to this comment

  12. cj Says:
    October 27th, 2009 at 1:46 am

    i find it hard to play a video from blob data type..
    please help me get my values from my DB through php
    then play it to flex

    thanks in advance
    -cj

    Reply to this comment

Comments