SQL Image field -> output as raw files issue

Four Stars

SQL Image field -> output as raw files issue



I am trying to take multiple files that were saved in a MS SQL Image field, and convert them back to their raw format.


I have tried following suggestions in the following thread: https://community.talend.com/t5/Design-and-Development/resolved-Create-file-from-a-blob-input-oracle...


My issue currently is that the job appears to be correctly looping through each IMAGE, but the tFileExportRaw is not correctly setting the filename. (See image1)


The following is the code in my tJavaRow

ByteArrayOutputStream baos = new ByteArrayOutputStream();
java.sql.Blob blob = (java.sql.Blob)input_row.Document;
byte[] buf = new byte[1024];
java.io.InputStream in = blob.getBinaryStream();
int n = 0;
while ((n=in.read(buf))>=0)
baos.write(buf, 0, n);
byte[] bytes = baos.toByteArray();

output_row.IMAGE = bytes;
output_row.filename = input_row.Fld1 + "-" + input_row.DocId + "." + input_row.FileExtension;

System.out.println(((String)output_row.filename)); //this correctly displays each file name.

tFlowToIterate is set at defaults

See image2 for my tIterateToFlow setup.


Finally, the tFileOutputRow filename is set to:   "C:/dev/DMSOut/" +  row3.filename

With this setup, no value (null) is being passed through to the row3.filename, and the files overwrite each other leaving 1 file named "null".


I also tried exactly as the previously linked post instructed, and only the last item's filename is passed through. Thus, the files all overwrite eachother and I am left with 1 file.


Forteen Stars

Re: SQL Image field -> output as raw files issue

You don't need use tIterateToFlow in case if You want to store each file separately 


in combination with flow output component create file once, but not for each row


You must use tFlowToIterate and do iteration for each row independent


as variant:


tFlowToIterate -> on ComponentOk -> tJava (assign global variable to output column) -> tFileOutput (with iterational name)


this is will work for each iteration independently 

Four Stars

Re: SQL Image field -> output as raw files issue

I have tried your advice as best as I could, and have not been successful getting the job to generate unique files for each row (with a dynamic filename as set in the tJavaRow).


Could you elaborate on "You must use tFlowToIterate and do iteration for each row independent" ? How do I connect the tFlowToIterate to my tFileOutputRaw ?



Forteen Stars

Re: SQL Image field -> output as raw files issue



Screen Shot 2018-10-05 at 01.37.22.png


tJava - it is your code

tJavasFlex_2 - dummy connector




filename in tFileOutput

Screen Shot 2018-10-05 at 01.38.14.png



Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables


How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration


Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.