Skip to content

File Download

Johannes Heucher edited this page Jun 13, 2022 · 2 revisions

UseCase: User downloads arbitrary files

Exemplified description of an architecture when the goal is to store and download arbitrary files.

Table of Contents

Step 1: Create File and Meta Data

There are no special requirements for creating files imposed by Xyna. Files could be created outside of Xyna or using some project specific Coded Service etc.

When creating text files it is possible to use the instance operations of the Datatype xfmg.xfctrl.filemgmt.ManagedFile (writeFromDocument). Choose the correct encoding when writing text.

If the goal is to be able to choose from files to download in a project GUI, it makes sense to store associated file meta data in a Storable. Meta data could contain file name, location, author, size, encoding/characterset, comments, etc.

Step 2: View Files

Show existing files by using the Storable containing the meta data from step 1.

Step 3: Prepare transient Managed File for Download

Use the operation "store" from the Service Group xfmg.xfctrl.filemgmt.FileManagement to put an arbitrary file into the Xyna File Management. The resulting ManagedFileId will be needed in step 4. The purpose of the Xyna File Management is only for temporary file storage (until the file is "consumed", i.e. downloaded). After storing the file in Xyna File Management, it is valid for 30 minutes (configurable using Xyna Property "xyna.xfmg.xfctrl.filemgmt.default_timeout").

So typically the "Prepare Download Workflow" gets the meta data Storable id as an input and returns a ManagedFileId.

There is no special thing in Zeta to get a ManagedFileId. It's completely up to the project when and how to provide the GUI with this ID. Inside zeta.api.xo.xo-managed-file-id.ts, there's already a TypeScript representative for the Xyna data type xmcp.io.ManagedFileID, which should be used inside the projects.

Step 4: Download

This is not a workflow but an invocation of the http endpoint that expects the ManagedFileId as http parameter "p0".

With ApiService.download(managedFileId: XoManagedFileID), Zeta provides an easy way to download files via a ManagedFileId. This function directly starts the Browser's download process.

Remark: For the download-endpoint, the URL /XynaBlackEditionWebServices/io/download is used (due to Tomcat compatibility). For Apache, this URL has to be forwarded solely to /download.

Both, steps 3 and 4, are typically invoked with one click from the user to download the file.

Encoding

Technically knowledge about the encoding of the file is only necessary when the binary file content is transformed into characters (or vice versa). This is only the case in Step 1.

Notes

For file storage use a separate disk partition from where Xyna is installed to preempt full disk problems.

Clone this wiki locally