
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fetch PDF document and convert it to Base64
Hi all. Im kind of newbie in all these things.
I need to get a document from a URL with a parameter (e.g. http://localhost?id_document=1,
http://localhost?id_document=2
). I used the tFetchFile componente, but I did not find how to pass the query param to identify the document. Can someone help me?
Then, I need to convert that file to base64. Does anybody know what component I should use?
Thanks in advance.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI @Maxi Roldan , you can format directly you URI in tfileFetch : " http://localhost?id_document=" + global var of your id.
The you can use a tFileList on the local folder you store the document,
then you can use this routine for example to transform the content into base64 with the file path from tFileList :
package routines;
import java.nio.file.Files;
import java.nio.file.Paths;
/*
*/
public class File_managing {
public static String base64FromFile(String filepath) {
try{
byte[] incoming_file_data = Files.readAllBytes(Paths.get(filepath));
return Base64.encode(incoming_file_data);
}
catch(Exception err){
err.printStackTrace();return null;
}
}
}
Send me Love and Kudos

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI @Maxi Roldan , you can format directly you URI in tfileFetch : " http://localhost?id_document=" + global var of your id.
The you can use a tFileList on the local folder you store the document,
then you can use this routine for example to transform the content into base64 with the file path from tFileList :
package routines;
import java.nio.file.Files;
import java.nio.file.Paths;
/*
*/
public class File_managing {
public static String base64FromFile(String filepath) {
try{
byte[] incoming_file_data = Files.readAllBytes(Paths.get(filepath));
return Base64.encode(incoming_file_data);
}
catch(Exception err){
err.printStackTrace();return null;
}
}
}
Send me Love and Kudos

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeremy. Many thanks for your answer! It was really helpful. I need to convert the file without saving it on disk. Do you know how I can di this? Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI, you can use Use cache to save the resource on the tfilefetch to store the file on an input stream.
Send me Love and Kudos

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jeremy. Thanks again. How can I read that input stream? With a tFileInputDelimited? Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
you can try something like this to get the byte[] from input stream:
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (true) {
int r = ((java.io.InputStream)globalMap.get("tFileFetch_1_INPUT_STREAM"))).read(buffer);
if (r == -1) break;
out.write(buffer, 0, r);
}
byte[] ret = out.toByteArray();
then you convert to base 64
Send me love and kudos
