I have come across many posts on several forums on Native file download. Currently we have a java script Action in the Native File document module to achieve it. The module was an excellent one, however I felt that a more structured documentation would help developers implement a download functionality in Native Application seamlessly. Downloading a file in Native app is a good-to-have functionality. However, there could be many challenges to achieve the goal.
Downloading a file in native is as easy as downloading it in web. But in Native, alternatives need to be done. One such alternative will be explained in this blog.
I am going to explain in detail about the key areas that play a major role in downloading a file in Native Mendix application.
Prerequisites: Native File Documents – Download the module from Mendix Marketplace.
How?
Use ‘Download File’ JavaScript action to download a file in Native application
When someone who is new to Native app development might wonder why we need ‘From URL’ and where to fetch it from? Let’s see what these parameters mean.
- 1. From url: URL from which the file must be downloaded.
- 2. To file: Path to which the file must be downloaded.
- 3. Progress interval: Set this to 100 if used in UI.
- 4. Read timeout: Specify the timeout in ms for Read.
- 5. Write to log: If it must be logged, set this input to true else false.
From URL?
Create a REST service to get the file document as shown below
Authentication for REST API can be done using username and password or using custom token or any other mode. In this example, I have used username and password for authentication. ‘FileID’ or any other unique ID can be used as input query parameter from which the file document can be retrieved and sent as a response.
After Integrating the API, upload the file and check whether the file is infected or not. If the file is infected by malware, our Mendix Application gets the response from the service and it will remove the file and show a warning message to the users. Without this mechanism, our Mendix application will allow the file which is infected and it may lead to a breach, which would expose the entire network to the intruder.
To File:
The path to which the file must be downloaded.
Set the file path in which the file must be downloaded along with the file name as shown above. You can write your custom logic to fetch the Path where you want to save.
Now you’ll be able to download a file in Native application. This process of File Download in Native app actually proved to be real easy to implement and at the same time extremely effective as well. This method can be used as a base and can be changed depending on the use case of the application. I am delighted to share this with our Mendix Community, and I am sure this will be useful when you want to download a file in Native App. Happy Coding!