Jump to content
Changes to the Jaspersoft community edition download ×

print image from postgresql bytea field using ireport


cmac

Recommended Posts

Hello,

I have seen several variations on this problem but I still don't have a solution.  I have read this comment which says it is not possible to use the standard java.io.InputStream (field) and java.io.InputStream (image) combo - http://stackoverflow.com/questions/8430313/displaying-image-in-ireports-using-postgresql - it clearly says "In PostgreSQL the bytea type is not a BLOB, and you can't use a stream."

I have next tried to convert my bytea field to an image but I don't know how.  None of the expression code I'm trying works.  I'm not a java programmer so I'm stuck.

Can anyone please help?

 

Link to comment
Share on other sites

  • 1 year later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

i found a way to do this, but is not working at all, still working on it:

These are the step :

 

Create a Class with the next code :

import java.io.File;
import java.io.FileOutputStream;
import java.util.logging.Logger;

public class Images {

    private static final Logger log = Logger.getLogger("Images");

    public Images() {
    }

    public File convertBytes(java.io.InputStream objeto) {
        try {

            java.io.ByteArrayInputStream bais = (java.io.ByteArrayInputStream) objeto;
            String strBais = bais.toString();
            File file = new File("Foto.jpg");
            FileOutputStream fos = new FileOutputStream(file);
            int data;
            while ((data = bais.read()) != -1) {
                char ch = (char) data;
                fos.write(ch);
            }
            fos.flush();
            fos.close();
            return file;
        } catch (Exception e) {

            e.printStackTrace();
        }
        return null;
    }

 

2.- Add the image and Change the "Expression clase to java.io.File"

3.- In the "Image Expression" add new class.package.Image().convertBytes($F{FieldFromDatabase})

4.- Add the jar if needed and dont forget to add the imports on your properties report.

5.- Sometime is necesary to change the rigths where the image wil be allocated.

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...