Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
output_row.Parent_ID = input_row.Parent_ID; // Related object's Id
output_row.Name = input_row.Name; // The document's name such as xxxxx.docx or yyyyyy.xlsx or anything else
output_row.ContentType = input_row.ContentType; // Object's name such as Account, Task and so on
output_row.Body = null; // The place to put the conversion result
// In this case, I iterate over the input directory using a tFileList
File file = new File((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));
try {
// Read file
documentInFile = new FileInputStream(file);
byte documentData[] = new byte;
documentInFile.read(documentData);
// Convert bytes array to Base64 string to fill Body field
output_row.Body = new String(Base64.encodeBase64(documentData));
System.out.println("+++ File converted "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));
} catch (FileNotFoundException e) {
output_row.conversionCode = "FILE_NOT_FOUND";
output_row.conversionMessage = "File not found "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** File not found "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+e);
} catch (IOException ioe) {
output_row.conversionCode = "CONVERSION_ERROR";
output_row.conversionMessage = "Error converting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** Error converting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+ioe);
} finally {
try {
// Close and delete file after it has been successfully converted
if (documentInFile != null) {
documentInFile.close();
file.delete();
}
} catch (IOException e) {
output_row.conversionCode = "DELETE_ERROR";
output_row.conversionMessage = "Error deleting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** Error deleting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+e);
e.printStackTrace();
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
// Import de Apache Commons Codec for Base64 conversion of documents
import org.apache.commons.codec.binary.Base64;
output_row.Parent_ID = input_row.Parent_ID; // Related object's Id
output_row.Name = input_row.Name; // The document's name such as xxxxx.docx or yyyyyy.xlsx or anything else
output_row.ContentType = input_row.ContentType; // Object's name such as Account, Task and so on
output_row.Body = null; // The place to put the conversion result
// In this case, I iterate over the input directory using a tFileList
File file = new File((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));
try {
// Read file
documentInFile = new FileInputStream(file);
byte documentData[] = new byte;
documentInFile.read(documentData);
// Convert bytes array to Base64 string to fill Body field
output_row.Body = new String(Base64.encodeBase64(documentData));
System.out.println("+++ File converted "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH"));
} catch (FileNotFoundException e) {
output_row.conversionCode = "FILE_NOT_FOUND";
output_row.conversionMessage = "File not found "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** File not found "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+e);
} catch (IOException ioe) {
output_row.conversionCode = "CONVERSION_ERROR";
output_row.conversionMessage = "Error converting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** Error converting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+ioe);
} finally {
try {
// Close and delete file after it has been successfully converted
if (documentInFile != null) {
documentInFile.close();
file.delete();
}
} catch (IOException e) {
output_row.conversionCode = "DELETE_ERROR";
output_row.conversionMessage = "Error deleting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH");
System.out.println("*** Error deleting file "+(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"\n"+e);
e.printStackTrace();
}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
// Import de Apache Commons Codec for Base64 conversion of documents
import org.apache.commons.codec.binary.Base64;
In the job design shown , file list is directly connected to sleep and then to java row, how is the file read here?
tSleep is here to permit the connection between tFileList and tJavaRow (was developed for TOS 6.2.1)
In recent versions of TOS this design is not permitted anymore as tSleep must have an input flow to have an output flow.
So the design must be revisited.
However, using Attachment is not a best practice from a salesforce point of view.
You should consider using Files instead.
Unfortunately, tSalesforceOutputXxxx components are not able to deal with ContentVersion object (see this post https://community.talend.com/t5/Design-and-Development/Upload-content-files-into-Salesforce-using-Co...).
For now, the solution is to use DataLoader in script mode, driving operations from Talend.
If this is a subject for you and have any question, please open an other topic.
Good luck!
it does not work at all any update ???