General Discussion

Tech Talk: Implementation - Base64 File Uploads in Handlebars and Freemarker

  • 1.  Tech Talk: Implementation - Base64 File Uploads in Handlebars and Freemarker

    Posted 08-21-2025 09:42

    New Feature: File Upload Question Support in FreeMarker Document Templates

    We are excited to announce a powerful new enhancement to the FreeMarker templating capabilities within TrueContext: support for File Upload questions. This extension allows you to now include and handle files uploaded through File Upload questions dynamically in your FreeMarker templates, expanding the types of documents and reports you can generate effortlessly.

    What This Means for You

    Previously, FreeMarker templates could reference and embed images and other binary content only from Image, Sketch Pad, or Signature type questions. Now, with the enablement of the same functionality for File Upload questions, you can seamlessly include files users upload-for example, PDFs, photos, or other document types-as part of your dynamically generated reports, JSON messages, or integration payloads.

    How It Works

    The FreeMarker Template Language (FTL) enables you to access file metadata and content through the `answers` data node. For attachments like File Upload questions, you can easily reference:

    • `identifier` - The unique attachment ID within TrueContext.
    • `filename` - The system-assigned file name with its extension.
    • `contentType` - The MIME type of the uploaded file (e.g., `application/pdf`).
    • `bytes` - The Base64-encoded content of the uploaded file. This allows you to embed the file content directly into generated documents or JSON payloads.

    Example syntax for referencing an uploaded file in your FreeMarker template:

    ${answers.FileUploadQuestionID[0].filename}
    ${answers.FileUploadQuestionID.contentType}
    ${answers.FileUploadQuestionID.bytes}

    This makes it straightforward to incorporate uploaded files into PDF or Word reports or to include them in HTTP POST request bodies for downstream systems.

    Important Notes

    • The `bytes` property, now available for File Upload answers, contains the file content in Base64 encoding. This enables embedding files directly inside document outputs.
    • Reference support applies only to files uploaded by users in File Upload questions; it does not apply to files generated by document templates.
    • Be mindful of payload size limits, as embedding large files in Base64 increases document or JSON sizes.
    • FreeMarker documents can now fully leverage the rich binary content users submit, streamlining workflows and integrations.

    Benefits

    • Richer reports: Attach user-uploaded documents, images, or files to reports without separate handling.
    • Integrated workflows: Pass files directly to other systems in API payloads generated from FreeMarker templates.
    • Simplified templates: One template can handle text data and file content seamlessly.

    This addition is part of our commitment to continually enhance TrueContext's document generation flexibility and integration power. If you are using File Upload questions in your forms, now is a great time to start embedding those files directly in your dynamic reports and data outputs.

    For a full guide and examples, visit our FreeMarker documentation.
    #TechTalkImplementation #



    ------------------------------
    Ian Chamberlain
    Solutions Architect
    TrueContext
    ------------------------------


Reminder: Content posted to our Community is public content.  Please be careful not to post Intellectual Property that you do not have permission to share.  For more information please refer to our Terms Of Use