
Anonymous
Not applicable
2015-04-30
12:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] Create file from a blob input (oracle db)
Hi,
I would like to create a picture (.jpg) from the blob data of an oracle table.
I have an oracle input that connects to the table "Photo" and retrieve the column "data" of type Blob.
How can I create the picture with this Blob data ?
I tried with a tMap and tJava, but the tMap will convert the blob into an "Object", so I don't know how I can work with this...
Thanks in advance for the help
Thomas
I would like to create a picture (.jpg) from the blob data of an oracle table.
I have an oracle input that connects to the table "Photo" and retrieve the column "data" of type Blob.
How can I create the picture with this Blob data ?
I tried with a tMap and tJava, but the tMap will convert the blob into an "Object", so I don't know how I can work with this...
Thanks in advance for the help
Thomas
1,191 Views
- « Previous Replies
-
- 1
- 2
- Next Replies »
1 Solution
Accepted Solutions

Anonymous
Not applicable
2015-04-30
12:30 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is currently only one way to do this: use the custom component tLOBDownload
https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&pi=marketplace%252...
https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&pi=marketplace%252...
934 Views
15 Replies

Anonymous
Not applicable
2015-04-30
12:30 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is currently only one way to do this: use the custom component tLOBDownload
https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&pi=marketplace%252...
https://exchange.talend.com/#marketplaceproductoverview:gallery=marketplace%252F1&pi=marketplace%252...
935 Views

Anonymous
Not applicable
2015-04-30
12:46 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've not tried this with jpgs but I have recently been working with MS Docs stored in a db. I simply used the tFileOutputRaw to do this. Just supply it your blob data as an object and it should work.
934 Views

Anonymous
Not applicable
2015-04-30
08:35 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I actually started to reply to this before jlolling wrote his response. Since reading his post, I have double checked my response and have found that it isn't quite as easy as I made out. But I have a solution which makes it pretty straight forward.
The job I put together looks like this...
I am receiving an image (as a Blob) and an ID from the db input. The code in the tJavaRow converts the blob to a byte array. The byte array is then sent to the tFileOutputRaw and that produces the file successfully. The Java used in the tJavaRow is below....
ByteArrayOutputStream baos = new ByteArrayOutputStream();
java.sql.Blob blob = (java.sql.Blob)input_row.IMAGE;
byte[] buf = new byte;
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.ID = input_row.ID;
The job I put together looks like this...
ByteArrayOutputStream baos = new ByteArrayOutputStream();
java.sql.Blob blob = (java.sql.Blob)input_row.IMAGE;
byte[] buf = new byte;
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.ID = input_row.ID;
934 Views

Anonymous
Not applicable
2015-05-04
09:40 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both for your answers. I will try both solutions.
Thomas
Thomas
934 Views

Anonymous
Not applicable
2015-05-05
04:17 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Your method works fine rhall, the only problem (which in my case is quite important) is this:
I have my javarow linked directly to the fileoutputraw, and I defined the name that the file will have in the javarow... How can I get the value of the variable from the javarow in the fileoutputraw ? (I already tried with context, but I will save iteratively many photos, so the name is changing dynamically)?
Thanks in advance for the help!
Thomas
Your method works fine rhall, the only problem (which in my case is quite important) is this:
I have my javarow linked directly to the fileoutputraw, and I defined the name that the file will have in the javarow... How can I get the value of the variable from the javarow in the fileoutputraw ? (I already tried with context, but I will save iteratively many photos, so the name is changing dynamically)?
Thanks in advance for the help!
Thomas
934 Views

Anonymous
Not applicable
2015-05-05
05:06 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Thomas,
You can use the globalMap hashmap. Calculate the filename in your javarow component and then save it to the globalMap variable like below....
globalMap.put("filename", "myFile.jpg")
.... then when you want to use it in the file component, retrieve the value like below....
((String)globalMap.get("filename"))
Regards
Richard
You can use the globalMap hashmap. Calculate the filename in your javarow component and then save it to the globalMap variable like below....
globalMap.put("filename", "myFile.jpg")
.... then when you want to use it in the file component, retrieve the value like below....
((String)globalMap.get("filename"))
Regards
Richard
934 Views

Anonymous
Not applicable
2015-05-05
05:20 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi rhall,
Thank you very much for your time.
Actually, I already tried this solution, but even tough the system.out.println swears that the "filename" path is correct in the javarow, the tfileoutputraw gives me a nullpointerexception ...
With 3 iterations, here is a sample of my code:
output_row.PATH = context.dir_photos+input_row.CODE_LOGIQUE+".jpg"; //comes from a tmap
globalMap.put("filename", output_row.PATH);
System.out.println((String)globalMap.get("filename")); //works correctly
And the execution is the following:
connecting to socket on port 4057
connected
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
java.lang.NullPointerException
java.lang.NullPointerException
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
java.lang.NullPointerException
disconnected
I guess I missed something ?^^
Thomas
Thank you very much for your time.
Actually, I already tried this solution, but even tough the system.out.println swears that the "filename" path is correct in the javarow, the tfileoutputraw gives me a nullpointerexception ...
With 3 iterations, here is a sample of my code:
output_row.PATH = context.dir_photos+input_row.CODE_LOGIQUE+".jpg"; //comes from a tmap
globalMap.put("filename", output_row.PATH);
System.out.println((String)globalMap.get("filename")); //works correctly
And the execution is the following:
connecting to socket on port 4057
connected
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
java.lang.NullPointerException
java.lang.NullPointerException
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
/Users/talias/Desktop/mssql/photos/ULR_40244.jpg
java.lang.NullPointerException
disconnected
I guess I missed something ?^^
Thomas
934 Views

Anonymous
Not applicable
2015-05-05
05:52 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah yes, I forgot about this. There is a hack to get round this irritating issue with dynamic file names. You need to use a tFlowToIterate followed by a tIterateToFlow. I have changed my job to look like below....
In the tJavaRow I have created an extra String output where I create and output my filename. The tFlowToIterate puts the byte[] content and filename string into the globalMap hashmap. Then the tIterateToFlow takes them one row at a time and creates a flow out of them. This is then sent to the tFileOutRaw and allows it to create a new file for each row.
The tIterateToFlow is configured as below....
The tFileOutputRaw is configured as below....
This should work 🙂
The tIterateToFlow is configured as below....
The tFileOutputRaw is configured as below....
This should work 🙂
934 Views

Anonymous
Not applicable
2015-05-05
06:17 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
-POST EDITED-
I thought I had an error, but it looks like I also had to cast my row.FILEPATH to string (not just the row.IMAGE).
It finally works, you helped me a lot, thank you very much !
Thomas
I thought I had an error, but it looks like I also had to cast my row.FILEPATH to string (not just the row.IMAGE).
It finally works, you helped me a lot, thank you very much !
Thomas
934 Views

- « Previous Replies
-
- 1
- 2
- Next Replies »