Static file in web app

We are working on a DHIS2 web app which has an Excel template file with certain metadata information. We allow uploading of Excel files filled with data - while uploading we use the template file for validating the uploaded file. Now, the template file is part of source code, means, it is part of the compiled app.

Is there any way so that we can have the Excel template out of the compiled app, so that if any update in the template file - we can just replace the file and the app continues working without compilation?

Does the dataStore allow Excel files instead of raw JSON?

@Mahmud no, the dataStore only supports JSON types. You can use the fileResources API to upload a file into DHIS2 (see the docs)

1 Like

Thanks @austin we have already used the file resource.
Although I am curious to know is there any limit on number of files that can be uploaded?
Any DHIS2 settings that we may have to tweak if the number of files/size exceed?
What is the folder where files are uploaded?

@dhis2-backend should be able to answer that for you!

Hi @Mahmud ,

There are no limits to number of files uploaded, for size, I think this might be restricted through your webserver like nginx, etc. But in DHIS2 we have no set limits at the moment.

Files are saved in your DHIS2_HOME folder, unless your instance is configured to use a cloud provider. In the latter case, files are saved in the cloud as configured in dhis.conf.

A last note: Files can be uploaded to one of several “domains”. Each domain decide how the file is used. For example, files uploaded as a data or attribute value will only be accessible to some people. However, the domain called DOCUMENT are the one I would assume you want to look at. These are static files available to every logged in user, in theory.

1 Like

Hi @Stian ,
I see two APIs - api/fileResources & api/documents. Are they same? Somewhere I read that file resources uploaded must be ‘linked’ to any entity inside DHIS2 otherwise they may get deleted in 2 hours.

I am giving my scenario - an external application will upload some data as a ‘document’ (say CSV) via API. Later at some point (maybe 2-3 days later) a custom DHIS2 web app will look for this file and extract and import data into tracker.

So in my scenario when files are uploaded - we cannot link it with any resource immediately
any idea?

1 Like

Hi @Mahmud , sorry for the late reply.

Yes, any file you upload will need to be related to a resource inside dhis2. On the backend, document and fileResources are the same. A FileResource is a reference to a file, while DataValue, Document, etc are using that reference/fileResource to “have” a file.

If you upload something as a document, that is sufficient. We do have a cleanup job that would look for FileResources without any attachments, and remove them.

1 Like