« Merry Christmas! | Main | Happy New Year 2009! »
BLOB from Java to Flex via BlazeDS
| By Rich Tretola | December 31, 2008 | |
| 13,484 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 | 20 Comments »









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:
January 1st, 2009 at 10:21 am
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
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
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
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
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
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:
August 24th, 2009 at 3:54 am
Please share the code
Reply to this comment
February 5th, 2009 at 7:44 pm
I sent you an email, please reply with your code sample.
Reply to this comment
ragin Reply:
August 24th, 2009 at 3:53 am
please share the source.
Reply to this comment
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
Fabrice Reply:
March 11th, 2010 at 12:02 pm
How you send an array of bytes from Java to Flex?
Reply to this comment
March 16th, 2009 at 4:46 am
Who can give me a copy of the source code . thanks a lot.
Reply to this comment
March 16th, 2009 at 4:46 am
Who can send the source code . thanks a lot
Reply to this comment
Rich Tretola Reply:
August 24th, 2009 at 7:29 am
There is no additional source code. Everything is in the original post. Just those 3 lines!
Reply to this comment
August 3rd, 2009 at 11:56 am
Useful tip,, Thanks
Reply to this comment
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
sathish Reply:
October 31st, 2010 at 4:09 pm
you need full code of both flex and java code
mail me i send u….
utopianmca@gmail.com
Reply to this comment
November 9th, 2010 at 7:13 am
Need a help.
I m making an application using flex java and mysql
The need for this application is to store xlsx and docx files to the mysql database. I am using BLOB data structure to store the file. Can you help me writing the code at java side. I am using BlazeDS too.
my email is tanwani.shreshth@gmail.com
Thanks will highly appreciate your help
Reply to this comment
January 21st, 2011 at 1:14 am
Hi,
I would like to know if you would be interested in a 6 + Months long contract with an Investment Bank in London. We’d like to know if you might be interested in a new contract opportunity, as we are currently recruiting for a “Java flex Developer”. Please send me your updated resume on Ashutosh@dataincuk.com
Reply to this comment