Extending IQA Functionality: File Download and Preview

As a new developer at John Consulting, I’ve quickly come to appreciate the robust capabilities of iMIS—it's a powerful system that handles most tasks right out of the box. However, there are areas where custom solutions can add significant value. One such area is interacting directly with file fields in IQA queries.

Understanding the Challenge

While iMIS excels in data management and reporting, its support for files in IQA queries is limited. The component lacks native support for downloading or previewing files directly within queries. For example, when a query includes a panel with a file upload field, attempting to display the content results in no visible output. Recognizing this limitation, we identified an opportunity to enhance the user experience, particularly in scenarios involving access to and sharing of documents through IQA queries, such as a board for posting downloadable articles.

The PDF downloader utility was developed to address this challenge, with careful attention to iMIS-specific hurdles such as permission control and integration with the system’s existing functionality


Integrating with the IQA Query

To integrate the PDF download and preview functionality, I first ensured the IQA query was correctly configured. This involved setting up a panel to accept file uploads and linking it to the IQA query as its data source. While the file upload field is not visible within the IQA itself, it can be accessed via an API call. With the field defined, the next crucial step was to make the IQA query accessible through the RESTful API, allowing for retrieval of relevant document data.

After setting up the query, I added custom display properties, including a download button to initiate PDF downloads and a preview feature that allowed users to view the document before downloading. These buttons triggered client-side code to execute the defined operations.


Client-Side Program

The client-side code starts by making an API call to retrieve data from the relevant IQA query. The response contains a collection of items, each representing a row in the IQA. The script then iterates through these items to locate the one that matches a specific row identifier. Once the correct item is found, it checks for the property containing the Base64-encoded PDF file. The script then follows a multi-step process to handle this file. First, the Base64 string and file name are extracted from the data. The Base64 string is decoded into a binary Blob, which is a binary large object that represents the data as a raw stream of bytes. For users who wish to view the PDF in their browser, the Blob is embedded in an iframe for immediate preview, with a loading state shown until the document is ready. For those who prefer to download the file, a download link is generated, and a simulated click triggers the download. Once the operation is complete, the system cleans up any temporary elements that were used during the process.

Additions and Revisions

This project posed several challenges, with one of the key difficulties being ensuring that the download and preview functionality adhered to the permission levels set by the IQA. iMIS provides fine-grained control over data access, so it was crucial that the solution respected these permission settings. Initially, I sourced the data directly from the panel, but this approach failed to meet the necessary security requirements. To address this, I adapted the solution to source the data from the IQA itself, ensuring full compliance with iMIS’s permission settings and properly handling the different response format.

Another challenge I encountered during the transition from using the panel API to the IQA was the absence of the ordinal field. The ordinal field is crucial as it uniquely identifies the position of an item or row in a dataset, allowing the script to correctly locate and reference the specific file or document associated with that item. Unfortunately, the IQA API response only includes properties that are explicitly shown, and it was undesirable to force the IQA to display the ordinal field. To address this, I stored the ordinal field in a hidden HTML element, enabling the program to access the correct item without requiring the IQA to expose the ordinal field. A loading indicator was also added to improve the user experience, making it clear when the system was processing their request. This helps prevent repeated clicks and provides feedback during the process.

Accessing the Solution

At John Consulting, we recognize the value of providing custom solutions that integrate seamlessly with the platform while adding valuable functionality for end-users. By offering this utility to iMIS customers free of charge, we aim to enhance the overall iMIS experience, making it even more powerful for organizations seeking efficient document management within the system. The PDF downloader and previewer solution can be implemented in your own iMIS system.

If you are interested in trying this solution for your organization, you can contact me at andrew@johnconsulting.net to receive a free sample. This offer is available at no charge to iMIS customers and is designed to improve your system's functionality by improving file management in IQA queries.

About the Author

You may also like these