How to store image into postgreSQL

Has anyone tried storing images in PostgreSQL using KNIME? How was the workflow? Below is my current workflow, I have no idea what should I do now.

Well I think it depends on what you want to achieve.

What I think won’t work is storing a plain image as jpg or png.

You definitely can store a link (although by the looks of it that’s not what you seem to be after) or probably an image converted to binary format.

There’s PNG to binary node:

And for non png you could use ImgPlus to png

To then get int into the DB there’s an example from @takbb here:

In general I think you have to set the column in your DB to type binary in the insert node.

4 Likes

I totally agree with Martin. You have to convert the images into binary format before you can store them in a database.

But be sure if you have many of them it may bloat your DB.

May I know is there any way to convert binary object?

Check the link Martin provided

1 Like

@Is_celine you can create an entry in a PostgeSQL database like this

CREATE TABLE images (
    id NUMERIC(5),
    image_binary BYTEA
);

And then upload a binary file. I adapted an example by @takbb .

1 Like

Now i having an issues in converting binary format, there’s no data under the out_image_binary. I have formatting the image into PNG format then use PNG to Binary Objects node to convert it, but it couldn’t work.

I don’t have a computer with me right now as I’m traveling, but looking at the screenshot: are you sure images are of type png (from Knime data type perspective)?

Can you use imgPlus node I shared above to convert image column to png and then use that to turn into binary?


I’m not sure is it correct cuz there is missing value under the out_image_binary column

What’s the Java snippet doing?

1 Like

Convert it to PNG format. If I did not use this code, the ImPlus node could not connect to PNG to binary object