<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I encode a csv file to base64? in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325673#M95247</link>
    <description>&lt;P&gt;Thank you sir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked, I was trying to figure out how to add import statements in tJavaRow component. Now it's all good and working.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Nov 2017 14:33:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-11-13T14:33:06Z</dc:date>
    <item>
      <title>How do I encode a csv file to base64?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325669#M95243</link>
      <description>&lt;P&gt;Hi I'm relatively new to talend and I want to encode a file of .csv format to base64. I am able to convert the string inside the .csv file but want to encode the entire file. Something like this in the link &lt;A href="https://www.freeformatter.com/base64-encoder.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://www.freeformatter.com/base64-encoder.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 09:04:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325669#M95243</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T09:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I encode a csv file to base64?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325670#M95244</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;Place this piece of Java code in a tJavaRow (in this example, the filename is in the current row):&lt;/P&gt; 
&lt;PRE&gt;// Get file from Document_ID + Name
String filename = input_row.Document_ID+"_"+input_row.Name;

//File file = new File((String)globalMap.get("ftpLocalDirectory")+"/"+(String)globalMap.get("ftpFilename"));
File file = new File((String)globalMap.get("ftpLocalDirectory")+"/"+filename);
FileInputStream documentInFile = null;

try {           
    // Read file
    documentInFile = new FileInputStream(file);
    byte documentData[] = new byte[(int) file.length()];
    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 "+filename);
} catch (FileNotFoundException e) {
	output_row.conversionCode = "FILE_NOT_FOUND";
	output_row.conversionMessage = "File not found "+filename;
	System.out.println("*** File not found "+filename+"\n"+e);
} catch (IOException ioe) {
	output_row.conversionCode = "CONVERSION_ERROR";
	output_row.conversionMessage = "Error converting file "+filename;
	System.out.println("*** Error converting file "+filename+"\n"+ioe);
} finally {
	try {
		// Close and delete file after conversion
		if (documentInFile != null) {
			documentInFile.close();
			//file.delete();
		}
	} catch (IOException e) {
		output_row.conversionCode = "DELETE_ERROR";
		output_row.conversionMessage = "Error deleting file "+filename;
		System.out.println("*** Error deleting file "+filename+"\n"+e);
		e.printStackTrace();
	}
}&lt;/PRE&gt; 
&lt;P&gt;This is a travial solution, but it works.&lt;/P&gt; 
&lt;P&gt;Hope this helps.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Note: the conversion result goes to a field of the output row (Body). You just have to write the&amp;nbsp;filed content to the desired file.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 19:16:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325670#M95244</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2017-11-10T19:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I encode a csv file to base64?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325671#M95245</link>
      <description>&lt;P&gt;How can I get Document_ID and Name? Am using tFileInputRaw to connect to the tJavaRow. I can only see content from tFileInputRaw. Thank you very much for the repsonse.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2017 20:38:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325671#M95245</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-10T20:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I encode a csv file to base64?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325672#M95246</link>
      <description>You need to adapt the example to your use case.
&lt;BR /&gt;Forget Document_ID.
&lt;BR /&gt;In your case you may retrieve the filename from tFileInputRaw using "(String)globalMap.get("tFileInputRaw_1.FILENAME_PATH")".
&lt;BR /&gt;Now you just need to replace the path or the filename.
&lt;BR /&gt;For example, replace ".csv" by "_base64.csv" to have a new file arr the same place than the original one.
&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Nov 2017 21:06:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325672#M95246</guid>
      <dc:creator>TRF</dc:creator>
      <dc:date>2017-11-10T21:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I encode a csv file to base64?</title>
      <link>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325673#M95247</link>
      <description>&lt;P&gt;Thank you sir,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked, I was trying to figure out how to add import statements in tJavaRow component. Now it's all good and working.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 14:33:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/How-do-I-encode-a-csv-file-to-base64/m-p/2325673#M95247</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-11-13T14:33:06Z</dc:date>
    </item>
  </channel>
</rss>

