Showing posts with label attachment. Show all posts
Showing posts with label attachment. Show all posts

Saturday, January 31, 2026

Download Resumes from Taleo

Taleo stores resume files or resume attachments in base64gz format at rest. The WriteBase64StringToBinary peoplecode file function will do only half of the job as it will not take care of uncompressing the gz format.

One option could be to use the peoplecode WriteBase64StringToBinary to get the decoded but compressed string and then use another 3rd party command line or java command line to uncompress the file.

Following method shows performing the decryption using delivered java classes.

Local JavaObject &fileOutgz, &gzFile, &fileIn, &fileOut;
Local JavaObject &gzipIn, &filebuffer, &decoder, &bytes_decoded;
Local string &gzFilePath;
Local number &byteCount;

   try

        /* some location to write the decoded but compressed file */
      &gzFilePath = "e:\\temp\\resume.gz";

      /* Get the Java Base64 decoder instance */
      &decoder = GetJavaClass("java.util.Base64").getDecoder();

      /* Decode the string into a byte array */
     /* &encoded_string is the value received from Taleo */
      &bytes_decoded = &decoder.decode(&encoded_string);
      &fileOutgz = CreateJavaObject("java.io.FileOutputStream", &gzFilePath);
      &fileOutgz.write(&bytes_decoded);
      &fileOutgz.flush();
      &fileOutgz.close();

      /* Create a FileInputStream for the compressed .gz file */
      &resumeFilePath = "e:\\temp\\resume.pdf";
      &fileIn = CreateJavaObject("java.io.FileInputStream", &gzFilePath);
      &fileOut = CreateJavaObject("java.io.FileOutputStream", &resumeFilePath);

      /* Chain it to a GZIPInputStream to decompress as it reads */
      &gzipIn = CreateJavaObject("java.util.zip.GZIPInputStream", &fileIn);

      /* Use a byte array to read chunks of decompressed data */
      &filebuffer = CreateJavaArray("byte[]", 1024);

      /* Read decompressed bytes until the end of the stream */
      &byteCount = &gzipIn.read(&filebuffer);

      While &byteCount > 0
         /* Process the uncompressed bytes, write to file */
         &fileOut.write(&filebuffer, 0, &byteCount);
         &byteCount = &gzipIn.read(&filebuffer);
      End-While; 

      /* Close the input streams to release resources */
      &gzipIn.close();
      &fileOut.close();
      &fileIn.close();

      &gzFile = CreateJavaObject("java.io.File", &gzFilePath);

      /* delete the temporary gz file */
      If &gzFile.exists() Then
         &gzFile.delete();
      End-If;

   catch Exception &ex      
        /* handle error conditions here */
          &bError = True;
     
   end-try;


Monday, March 6, 2023

Mass upload/download files

Recently I was presented with a requirement wherein the user should be able to mass upload files from their local workstation to PeopleSoft and then mass download the files from PeopleSoft to their local workstation. The files would be stored in the database record.

I am running PT 8.59.x and PeopleSoft does provide a couple of functions MAddAttachment and DetachAttachment for this exact requirement. 

The MAddAttachment function is pretty straight forward. I was able to call it via FieldChange event, where in a dialog box is presented to the user to select a single file or multiple files and the files are loaded to the URL value provided as part of the function parameter. The function also has a parameter which can limit the number of files uploaded at a time. Just like the AddAttachment function this function also converts the filenames which have special characters like a space, amersand, plus sign etc. to underscores. More info about this under the "Understanding the File Attachment Functions" and "File Name Considersations" section in Peoplebooks.

For my requirement I was displaying the files loaded via MAddAttachment in a grid on the page. Now I provided another button, and on FieldChange of this button the plan was to invoke DetachAttachment to run through the files in the grid and download them locally to the user's workstation. For some reason this does not work. The code would run through the grid but would download only the last file in the grid, no errors anywhere.  So following is what I did to get around this limitation.

I am using GetAttachment first to read through the grid rowset and download the files to a temporary location on the server. I am programmatically creating a folder structure to download the files to. Then I am using java clases to compress or zip up the files in the temporary folder. Process to compress files available here. Then I am using PutAttachment function to upload the single compressed/zip file back into the database. Finally I am calling DetachAttachment to download the compressed/zip file to the user's local workstation. As part of post-cleanup I am using DeleteAttachment to delete the compressed/zip file from the database and then using RemoveDirectory to delete the temporary location created on the sevrer to download the files to.