Dynamic OptionField

Objective

In my app, the user can upload a file which is used for the following steps. This file is reused across multiple entities of the app, so it is automatically saved on a VM. The file can get quite heavy, so I want to allow the user to only upload it once and then reuse it in future app entities.

Ideally, the user would have 2 options: upload a new file, or select a previous one from a dropdown menu. How can I dynamically populate this menu, based on the files available on the VM at a given location?

Workaround 1

Instead of an OptionField, the user enters the name of the file in a TextField. However this fails if there’s a typo.

Workaround 2

I regularly go on the VM, get the list of files, update the options of the OptionField and re-publish the app. That would require very regular maintenance…

Workaround 3

Add a “get files” button that returns the list of files on the VM as a json, the user goes through the list, finds the name of the file they want, and enter that name in a TextField. That’s a bit safer than the first workaround but still not fullproof, and quite cumbersome for the user.

Solution

Any better ideas?

(fellow engineer at a client of viktor.ai)

You made me think of some more possibilities.

Definitions

file: file uploaded in Entity A and stored (presently) on your VM.

Entity A: entity where the file is uploaded.

Entity B: entity in which the file must be accessed.

Potential Workaround 4

If the file is not too big for your purpose, you could try to store the file in entity A using a Filefield.

You could then use the API to get a list of entities type A for the user to select (within entity type B).

Then access the file from the parametrization (I believe it is possible but I may be mistaken).

Potential Workaround 5

If for any reason, you do not want to store the file itself in an entity (ex. too big).

You could try to store the file name in the parametrization of the entity A.

You could then use the API to get a list of entities type A for the user to select (within entity type B) .

Then access the file name from the parametrization.

Limitation

I do not have access to your use cases, or constraints, so these workarounds may not be suitable to your use case. I hope however it can contribute a bit.