Configuring User File Uploads

Overview

Users can upload their own files into PhixFlow using actions. This can be done using either a  Table-action which links to a  File Collector, or an  Actionflow containing a file upload node. This will allow users to:

  • Upload images/files and store the details of where to access them as a record.
  • Upload files to be used in an analysis model. These files can be made available for users to download.

Example

In a simple contacts application, it is possible using file uploads to:

  • Allow an application user to upload their own image against a contact:


  • Bulk upload Excel files containing multiple contacts to appear within an application.
  • Download files stored on the server. These could be previous file uploads. 

Solution

Images and files are stored on the server when uploaded by a file collector. These files are placed into a standard directory and need to be moved into an appropriate directory which can be accessed by the front end. See your system administrator for help creating these directories.

Once the new directory has been created, the following is required:

  1. an action configured to upload a file
  2. an analysis model containing a file collector and a table
  3. a task plan that runs the analysis model

This is a worked example to set up a model that collects an uploaded file, moves it, and all the upload subdirectories, to the required new directory using an archive location on a file collector, to tell the collector where to move the file once it has been processed.

When files are uploaded via an action, they are initially stored under the default upload directory, this is specified in your system configuration. For example:

 /opt/phixflow/data/phixflow/upload 

A subdirectory is created for each uploaded file, in the form:

/opt/phixflow/data/phixflow/upload/[tag]/in/[uploadDate]/[uploadID]/[filename]

where

  • [tag] is the tag specified by the action or file collector,
  • [uploadDate] is the date of upload represented in a numerical string,
  • [uploadID] is a unique string used to identify each file, and
  • [filename] is the name of the uploaded file.

When uploading files through the front end we aim to move the files to a location under (either directly or via soft link) the below directory while preserving these subdirectories in order to uniquely reference each file.

/opt/phixflow/data/phixflow/datalink

1. Creating the Action to Upload a File

  1. In the File Upload section, tick File Upload and enter a Tag Expression (e.g. "contact").
  2. The exact tag used does not matter but needs to be used later to reference the upload location.
  3. Ticking File Upload means that running the action will trigger a file upload prompt, allowing the user to select a file to upload:

2. Creating the Analysis Model

  1. Create a new analysis model and create a  File Collector. Apply the following settings:


PropertySet toNotes
Source TypeSpecified Directory
File Type:File Details OnlyThis means the file collector will not attempt to bring through any data (as it would for eg. an Excel file), but will collect the details of the file (eg. file name, file location).
File Location Strategy:All Files in Folder

Ignore Base Directory

TickedBy default, Ignore Base Directory is unticked, and so PhixFlow assumes that the archive directory location is a subdirectory of the base location specified in System Configuration (normally set to /opt/phixflow/data/phixflow/archive). We want to move files to a location outside of this set default, so Ignore Base Directory must be ticked.
Input Directory Expression
"/opt/phixflow/data/phixflow/upload/[tag]/in"

e.g.
"/opt/phixflow/data/phixflow/upload/contacts/in"
  • where [tag] is the tag expression used on the action (e.g. "contacts"
Directory Pattern Expression
"." + _context._fileUploadId + "."
The internal variable _context._fileUploadId is available when running a file collector, and returns the unique ID string that has been assigned to each uploaded file.
The expression "." will match for any string of zero or more characters (see Regular Expressions). So the full expression "." + _context._fileUploadId + ".*" matches any directory path that contains the upload ID somewhere in it.
File Pattern Expression
".*"
This means the file collector will collect any file it finds. If you want to specify a certain file type, you can do that here – eg. a File Pattern Expression of ".pdf" means only PDF files will be collected.
Archive Directory Expression


"/opt/phixflow/data/phixflow/[dir]"

e.g

"/opt/phixflow/data/phixflow/ContactImages


Where [dir] is the directory used to store the uploaded files.
This means that once the file has been processed, the file collector will search in the directory specified by the Input Directory Expression, find all subdirectories that match the Directory Pattern Expression, and move them into the directory used to store the uploaded files. The subdirectory structure will be preserved within the new directory.

For more information on how to create this new directory speak to your system administrator.

2. Next create a  Calculate Table from the  File Collector.


3. On the new table, create 4 attributes with the following settings:



Attributes
Property1234
NameUploadDateUploadIDFileNameFileLocation

Type

StringStringBigstringString
Length1050
1000
Expression
toString(today(), "YYYYMMdd")


_context._fileUploadId


in._fileName


'url("https:datalink/[dir]/" + _out.UploadDate + "/" + _out.UploadID + "/" + _out.FileName + '")'

where _[dir] is the directory used to store the uploaded files

PurposeConverts today's date
into a string

uses context variable

to return the upload ID string.

The internal variable _fileName is available when running a file collector, and returns the name of the file that has been uploaded. It must be prefixed with a pipe name.

Example

'url("https:datalink/ContactImages/" + _out.UploadDate + "/" + _out.UploadID + "/" + _out.FileName + '")'

This expression uses the upload date, upload ID and file name to build the URL containing the directory path of the uploaded file after it has been moved by the file collector. The URL is what is referenced by CSS properties to display the image.

3. Creating the Task Plan

  1. Create a new task plan
  2. Create an analysis task which runs the above table
  3. On the created action, in the Run Task Plan section tick Run Selected Task Plan, and add the new task plan.

This means that after the action prompts the user to upload a file

  • the table will be run,
  • which in turn runs the file collector
    • the file collector finds the file in the upload location and moves it to the new directory used to store the files
  • the table then pulls through the file details generating its new location in the attribute FileLocation. This attribute can then be used whenever the file needs to be referred to.

4. Referencing Images on the Server

Once the user has identified the correct directory to store the file, it can be referenced using a URL. This URL must be in the format:

url("[File Location]")

For example: 
url("https:datalink/MyProject/MyImage.png")

This URL is the value that needs to be stored and is referenced to display the image using CSS properties. Using the above example, the user stores the url of an image against each user in an attribute called 'ContactImage'. You can display this image on an area inside a card container using the following style settings:

  • Name: background-image
  • Expression: _form.ContactImage
  • Name: background-repeat
  • Expression: no-repeat
  • Name: background-size
  • Expression: choose size – could be 100%, 20px, auto (see Image Sizing)

Changing Images on the Server

To change the image displayed in PhixFlow, upload a replacement image with the same name. The new image overwrites the original image. The existing URL continues to work and displays the new image. If the image name changes on the server, you need to update all the URLs that point to it.

Browsers cache images, if this happens the image will not change on the front end. To resolved this clear your browser cache and refresh the screen to display the updated image.