Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Priyank2
Contributor
Contributor

Upload CSV format file into Salesforce using content versionobject through Talend

Hello,

I have an requirement to attach csv format file in salesforce using content version object.

can anyone please help me to know how it can be achieve using Talend?

Thank you in advance!

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable

You can do this using a tSalesforceOutput component and a bit of code (maybe used in a tMap) to convert your file to a Base64 byte array. Try this out in a sandbox first.

 

My tMap connected to my tSalesforceOutput component looks like this......

 

0695b00000LvjUOAAZ.png 

The "Lithium_Href__c" is a bespoke field that I added for other purposes (tracing between environments).

 

The routine I used to convert the file to a byte array is below....

 

package routines;

 

import java.io.File;

import java.io.IOException;

import java.nio.charset.StandardCharsets;

import java.nio.file.Files;

 

import org.apache.commons.codec.binary.Base64;

 

 

 

public class Base64File {

 

public static byte[] encodeFileToBase64Binary(String fileName) throws IOException {

  File file = new File(fileName); 

  byte[] encoded = Base64.encodeBase64(Files.readAllBytes(file.toPath()));

 

  return encoded;

}

}

View solution in original post

14 Replies
Anonymous
Not applicable

You can do this using a tSalesforceOutput component and a bit of code (maybe used in a tMap) to convert your file to a Base64 byte array. Try this out in a sandbox first.

 

My tMap connected to my tSalesforceOutput component looks like this......

 

0695b00000LvjUOAAZ.png 

The "Lithium_Href__c" is a bespoke field that I added for other purposes (tracing between environments).

 

The routine I used to convert the file to a byte array is below....

 

package routines;

 

import java.io.File;

import java.io.IOException;

import java.nio.charset.StandardCharsets;

import java.nio.file.Files;

 

import org.apache.commons.codec.binary.Base64;

 

 

 

public class Base64File {

 

public static byte[] encodeFileToBase64Binary(String fileName) throws IOException {

  File file = new File(fileName); 

  byte[] encoded = Base64.encodeBase64(Files.readAllBytes(file.toPath()));

 

  return encoded;

}

}

Priyank2
Contributor
Contributor
Author

Hello Rhall,

 

I tried but facing error shown below :

0695b00000LvwLFAAZ.pngThis is my flow design:

0695b00000LvwLUAAZ.png0695b00000LvwLeAAJ.png 

0695b00000Lvw95AAB.png 

Can you please me by correcting in flow?

 

thanks and regards,

Anjali Kumari

Anonymous
Not applicable

Did you create the Routine that I posted? The code in my previous post.

Priyank2
Contributor
Contributor
Author

Yes I created routine as you mentioned earlier( and for help I am using 7.2 talend version).

 

0695b00000LvxdUAAR.png 

Anonymous
Not applicable

Your Routine is called Base64File, but your use of it refers to Base64 and not Base64File. This is my fault. When I showed a screenshot, my Routine was called differently the to example I shared in code. Adjust this in your tMap and you should get a bit further.

Priyank2
Contributor
Contributor
Author

Hello Rhall,

 

Yes it worked now Many Thanks 🙂 but now I am getting NoSuchFileException can you also help me know how to pass file in versiondata field? For example I have a File named Testrecords.csv (It contains 2 columns : Id,Name).

Anonymous
Not applicable

I missed this in your screenshot. You are not meant to read the file, you just need to pass the path to the file and filename. The routine reads the file and does the work there. Essentially, the value you get from the tFileList should be sufficient.

Priyank2
Contributor
Contributor
Author

I understand you but how to implement it in job facing difficulty,now tMap part is OK but how to design flow before it? can you please share full job to know exactly which component to use in order to pass filepath?

 

For an example : I used tFileList to select file ---->this is OK

now what is right approach after this before tmap?

0695b00000LwCJ0AAN.png 

Many Thanks!

 

Anonymous
Not applicable

If you connect a tFixedFlowInput to your tFileList, then use the globalMap variable from the tFileList in the schema of your tFixedFlowInput, you can pass the file path to the routine. It would look somewhat like this....

 

0695b00000LwCfQAAV.png