Retrieve images from mysql DB

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieve images from mysql DB

r.pecori
I am trying to retrieve an image stored in the orbeon_form_data_attach table in mysql db.

file_content is a BLOB file but itd dimensions are lower than the actual imaged attached to the form. Moreover if I try the fllowing code it creates a JPG file but it is not openable in as an image saying: Not a JPEG file: starts with 0x3c 0x21.

Here it is my Java code:
String image= 97262dfd32946936723f722c1ebca3f40c6ad87e.bin;//value present in the DB

statement = conn.createStatement();
             
        rs = statement.executeQuery("SELECT file_content from orbeon_form_data_attach where file_name='"+image+"' order by last_modified DESC limit 1");
           
        rs.first();
        Blob blob =rs.getBlob(1);
       
        _log.info("Blob size: "+blob.length());//it prints correctly 449B
           
        byte[] imgData = blob.getBytes(1, (int) blob.length());
       
       
        FileOutputStream os = new FileOutputStream("/home/riccardo/CIAO.jpg");
       
        for (int b=0; b<imgData.length; b++)
       
        {  
           os.write(imgData[b]); // os is the instance of FileOutputStream  
        }  
        os.close();
       
          statement.close();
            conn.close();


Can anyone help????
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve images from mysql DB

r.pecori
This post was updated on .
I am running Orbeon Forms 4.0.0.rc1.201302120214 PE with development licence.

I am using Form Runner portlet in Liferay.

I noticed that uploading images in a form shown in tomcat preserves image dimensions in blob.

Whereas usinf liferay form runne rportlet to show the form, and uloading an image leads to store a binary file blob with dimensions different, 449B.

why? is there a configuration I am missing? or is it a bug and should I try a more recent version of orbeon?

 If I use a more recent jar it works but I have problems with waiting mask.
Can anyone help? It's quite urgent
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve images from mysql DB

Erik Bruchez
Administrator
We are not aware of this issue. Image uploads should work exactly the same whether you are accessing Orbeon Forms directly or via Liferay.

-Erik
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve images from mysql DB

Erik Bruchez
Administrator
Oh and by the way yes, I think it is better to use Orbeon Forms 4.2 rather than the RC build you are using.

-Erik
Reply | Threaded
Open this post in threaded view
|

Re: Retrieve images from mysql DB

r.pecori
Solved using liferay 4.2 thank you