Skip to main content
Skip table of contents

Working With Panel Files

Overview

This article outlines how to work with files stored in panels (or other binary-type data) using the iMIS connector in Power Automate and Logic Apps. Learn how to work with file data in iMIS - extract file data from panels, and import files and file metadata into iMIS panels. 

Technical Summary

Click to Display Technical / Developer Summary

Any input panel field of type "File" or "Binary" which is exposed by the iMIS connector for Power Automate cannot accept raw binary data - it will only accept a JSON object containing the following fields:

  • File – The actual file data - expressed as raw bytes or Base64-encoded file data. (The connector will dynamically detect Base64-encoding and fall back to raw bytes if Base64 data is not detected.)

  • FileName – The name of the file. Full file paths (/c/b/a.txt or C:\b\a.txt) are also accepted and the filename (a.txt) will be parsed automatically from the full path.

  • MimeType – The MIME type (aka "Content-Type" or "Media Type") for this file - if you are not sure, or the value is dynamic and not able to be determined, use application/octet-stream.

Use the Compose action in Power Automate to construct a JSON object and use that as the file input instead of the raw file data.

Example:

CODE
{
  "File": "AAAA+BBBB/CCCC===",
  "FileName": "MySampleFile.csv",
  "MimeType": "text/csv"
}



When outputting file data from iMIS to another source, only the file data is returned, so the "File" panel field variable should contain only the file data - the data is not wrapped in a wrapper object.

Encoding Warning

Power Automate has a tendency to automatically Base64-encode and decode binary data like file contents. If something isn't working, inspect your workflow runs to see if you need to manually encode or decode your data, or if the data may inadvertently be double-encoded.

It is not currently possible to fetch the file name or file type back out of a file field in a panel.

Problem

iMIS stores files inside panels in an encoded XML document behind the scenes. This XML document contains four fields:

  • File

  • FileType

  • UploadedFileName

  • FileContentType

This document is incompatible with Power Automate, as the following diagrams demonstrate.

Shown above, when sending a file from iMIS to Power Automate, we can simply discard the extra information that Power Automate does not have inputs for.

However, when sending a file from Power Automate to iMIS, we don't have the required fields:

Solution

We must therefore wrap the fields required by iMIS (the file and its metadata) in an object:

Creating a File Wrapper

Follow these steps to create a file description wrapper object in your Power Automate flow.

This example will use a OneDrive file as the source file, which is an output of the action OneDrive for Business > Get File Content Using Path.

Add the Compose Action

First, add a step before your iMIS panel step and after you have retrieved your file contents.

Choose the Data Operations > Compose built-in action:

You should see a field called Inputs. In this input field, copy and paste the following JSON template code:

JSON
{
  "File": "",
  "FileName": "",
  "MimeType": ""
}

Add File Data

To add the actual file contents, place your cursor in between the two quotes (""), and then choose the "File contents" variable (or whichever variable contains your file data).

Add File Name

To add the file name, simply follow the same steps as above, placing your cursor between the two quotes and selecting the variable that contains your file name.

File Paths Accepted!

You may also supply a file path (a file name which contains some folders before it, delimited by / or \ ). The connector will automatically parse out a file path and determine the correct file name.

Examples:

  • ABC.pdf → ABC.pdf

  • /Documents/Scanned Files/Scan-2022-01-01.pdf → Scan-2022-01-01.pdf

  • C:\Users\Bob\Documents\Sample.csv → Sample.csv

  • /MyFile.xlsx → MyFile.xlsx

This allows you to feed in a file path directly from a cloud storage provider such as OneDrive or Google Drive without having to parse out the filename manually.

You can also type a filename manually between the quotes. Note that this means the filename will be the same each time the automation runs.

Add MIME Type

You must also supply a MIME Type, sometimes referred to as a Media Type or Media Header.

Please refer to the following table for a list of common MIME Types:

MIME Type

Corresponding File Types

​application/vnd.openxmlformats-officedocument.wordprocessingml.document

​DOCX

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

XLSX

application/vnd.openxmlformats-officedocument.presentationml.presentation

PPTX

application/pdf

PDF

application/xml

XML

application/zip

ZIP

text/plain

TXT, LOG

text/csv

CSV

text/html

HTM, HTML

image/png

PNG, APNG

image/jpeg

JPG, JPEG

image/gif

GIF

image/bmp

BMP

video/mp4

MP4

application/octet-stream

Any (see below)

For additional MIME types, please refer to this MDN article.

Don't have or can't determine the MIME Type?

It's important to store the correct MIME Type with your file, so that iMIS knows how best to serve your content. (For example, if you specify that you have a PDF document, some browsers and mobile devices will display a preview instead of downloading the file).

However, in some contexts, you may not have the appropriate MIME Type. That's okay.

If you are unable to provide the MIME Type and you cannot enter a manual value because you'll be handling many different types of files with a particular automation, simply use the following "catch-all" MIME Type:

application/octet-stream

This instructs most browsers that this file should be downloaded, regardless of its content.

Using the Compose Action's Output

Once you have the three fields (File, File Name, and MIME Type), you can now use this "file object" inside of a "Create Panel" or "Update Panel" action.

Simply connect the "Output" variable from the Compose action into any "File" or "Binary" panel field.

You should always test your automations. In particular, verify that the file is written to the panel source successfully in iMIS, you are able to successfully download the file from the panel in iMIS, and that the file is not corrupt.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.