SQL Image field -> output as raw files issue

Four Stars

SQL Image field -> output as raw files issue

Hello,

 

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);
}
in.close();
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.

 

Thirteen 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 ?

 

Thanks!

Thirteen Stars

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

Hi,

 

Screen Shot 2018-10-05 at 01.37.22.png

 

tJava - it is your code

tJavasFlex_2 - dummy connector

 

tJavaFlex_1

row3.IMAGE=(byte[])globalMap.get("row2.IMAGE");

filename in tFileOutput

Screen Shot 2018-10-05 at 01.38.14.png

-----------

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.