Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to retrieve byteArray/blob from Data base?

Hi All,
Using Talend job , I need to retrieve images from data base to local system. Images are stored in DB as byte array.
Could any 1 please guide me on this.

Thanks In Advance
Chaya
Labels (2)
15 Replies
Anonymous
Not applicable
Author

Hi Chaya
Which DB do you use? What's the data type of the image column?
I guess maybe you have to write a custom routine which can retrieve binary from DB into file.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks Pedro,
I m using postgres, column data type is bytea.
I have referred, one of your post , where in you have given, "BlobDemoRoutine" to load images from local system to Data base by using "ByteArrayFromFile" method.
I want to do exactly reverse of this. If I play around with fileOutPutSteam and byte array in java routine that should get me the images back.. am I rite?
janhess
Creator II
Creator II

You probably need base64 encode/decode.
See https://community.talend.com/t5/Design-and-Development/resolved-Send-file-to-WebService/td-p/106745.
I've also posted a number of other solutions for images.
Anonymous
Not applicable
Author

Hi
package routines;
public class Write {


public static void ByteArrayToFile(byte[] input, String filepath) {
try
{
java.io.File fp = new java.io.File(filepath);
java.io.FileOutputStream fos = new java.io.FileOutputStream(fp);
fos.write(input);
fos.close();
}
catch(Exception err)
{
err.printStackTrace();

}
}
}

Create a job tPostgresqlInput--main-->tJavaRow.
Regards,
Pedro
Anonymous
Not applicable
Author

Thanks a lot Pedro & janhess.
Wel Pedro,
I just did exactly what ever you said. Job runs with out any error.. 0683p000009MACn.png & also a .png is created in the specified path
But When I try to open the image in the specified path, I cant see the image, its shows as error message content is corrupted or damaged..
Am I doing something wrong. Please correct me.

Thanks
Chaya
Anonymous
Not applicable
Author

Hi Chaya
Are you sure that the suffix of this image is png?
Maybe it is jpg or other file.
Regards,
Pedro
Anonymous
Not applicable
Author

Hey Pedro,
Yes I m sure, The file is .PNG only
I reconfirmed also, by uploading 1 .png to DB and again trying to download the same.
janhess
Creator II
Creator II

I think you can read it in as an object type and map this to an object typ output in a tMap. No coding required.
Anonymous
Not applicable
Author

Hi Chaya
I test it and it works fine.
Can you save a new image into DB?
We need to make sure the data in DB is correct.
Regards,
Pedro