[resolved] salesforce: upload file into attachement object fails

One Star

[resolved] salesforce: upload file into attachement object fails

Hi,
I have a problem uploading files in Salesforce into "Attachment" Object using tSalesforceOutput.
My file is well formatted because when I use another Loding tool it works (Dataloader).
My input file reference files stored in a windows network repository : "\\server\rep\file.doc" but when i run the job, it insert the row and consider that the file referenced in the standard salesforce column "BODY" is the title of the file instead of the real file.
Do you know if this is a bug or if there is a way to make talend recognise that the string value at the "BODY" column is the title of the file and not what is inside the file.
Thank you in advance,
Erwan

Accepted Solutions
One Star

Re: [resolved] salesforce: upload file into attachement object fails

OK, i fixed the problem by opening the file , converting inputstream into a byte table and use "commons-codec.jar" to convert file into base64.
I did that because i knew that salesforce old the file in base64 format so i supposed the talend object didn't make this final work for that specific standard "attachment" object.
Here is the code working fine. My files are all uploaded to salesforce (be carefull to have file smaller than 5 Mo):

File file = new File(input_row.BODY);
//File file = new File(input_row.DESCRIPTION);
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte;
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file);
}
// Close the input stream and return bytes
is.close();

Base64 tmp = new Base64();
output_row.BODY = new String(tmp.encode(bytes));
Regards,
Erwan

All Replies
Community Manager

Re: [resolved] salesforce: upload file into attachement object fails

Hi Erwan
Maybe the problem is caused by the windows network repository : "\\server\rep\file.doc", it is failed to open the remote file? Try to put the file on local machine and test again.
Waiting for your feedback!
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] salesforce: upload file into attachement object fails

Hi,
I have aleready tested that with the same results.
The talend component should recognise that the "BODY" column of the attachment object isn't a simple value column but a reference to a file.
When i see the code generated i read that the tsalesforceoutput doesn't diffrencies that type of column from the others.
Thank you for any help.
Regards,
Erwan
One Star

Re: [resolved] salesforce: upload file into attachement object fails

OK, i fixed the problem by opening the file , converting inputstream into a byte table and use "commons-codec.jar" to convert file into base64.
I did that because i knew that salesforce old the file in base64 format so i supposed the talend object didn't make this final work for that specific standard "attachment" object.
Here is the code working fine. My files are all uploaded to salesforce (be carefull to have file smaller than 5 Mo):

File file = new File(input_row.BODY);
//File file = new File(input_row.DESCRIPTION);
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte;
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file);
}
// Close the input stream and return bytes
is.close();

Base64 tmp = new Base64();
output_row.BODY = new String(tmp.encode(bytes));
Regards,
Erwan
Community Manager

Re: [resolved] salesforce: upload file into attachement object fails

Hi Erwan
Glad to see you resolve the problem by yourself and share the solutions, it will be nice if you can also report it on our bugtracker, our developer will fix it on next release.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] salesforce: upload file into attachement object fails

Hi All,
Does anyone know if this got fixed?
Thanks
Martin
One Star

Re: [resolved] salesforce: upload file into attachement object fails

II've just fallen into this issue. I originally used the file path for the body but have since noticed that is just how Dataloader have implemented the code. Talend seems to sent the file as is and let salesforce process it, so I have tried using the base64 encoded file contents but I'm still getting batch invalid. I am inserting the name, body, parentid but just can't get this to work.
I am using a slightly older version (will check when I get back to the office), so perhaps this has been resolved in newer versions...