How To Download Files to a Mobile Device

Description

This topic discusses two different techniques for downloading files (such as PDF, Video, Audio, Excel, Image files) to a mobile device so that the files are stored in the filesystem on the device and can be viewer later on (presumably when the device no longer has an internet connection) using the Native app associated with the particular file type.

The comments in this topic apply only to Cordova applications. Your Cordova application will need to load the following plugins: Cordova Open, Device, File, File Transfer.

The first technique uses the PhoneGap - File download action in Action Javascript. Using this action you can define an action that will download a list of files and store them in the filesystem on a mobile device. The action downloads a list of files returned by a Javascript function.

The second technique uses features of the List control to automatically download files when the List is populated. The data with which the List is populated should contain a field that has the URL for file you want to download. For example:

Filename

URL

pdffile1

http://alphafiles.s3.amazonaws.com/pdffile1.pdf

pdffile2

http://alphafiles.s3.amazonaws.com/pdffile2.pdf

pdffile3

http://alphafiles.s3.amazonaws.com/pdffile3.pdf

pdffile4

http://alphafiles.s3.amazonaws.com/pdffile4.pdf

etc...

To use this technique:

  1. Define a List control with a Detail View

  2. In the List builder, on the Fields tab, set the control type of the URL to LinkedFile

  3. In the List Builder, on the DetailView tab click on the smart field for the Media files (photos, videos, audio recordings, other) settings property.

  4. In the dialog that is displayed, check the Automatically download media a other linked files when populating this List property. This will cause all remote files (referenced by their URL, and identified by List columns that have a column type of Image, Video, Audio or LinkedFile) to be downloaded and saved in the filesystem on the mobile device when the List is populated.

    images/downloadlinkedfiles.gif
  5. You may also want to check the Automatically delete un-referenced files property. This will delete any previously downloaded files when the List is re-populated with new data and records in the List data no longer reference any previously downloaded files.

The advantage of this second technique over using the PhoneGap - File download action in Action Javascript is that the downloading of files is automatically handled for you.