This is especially useful for users who have stored many files in a kintone App, and wish to download all the files at once.
To make the bulk download easier, we will also use some libraries that are not on the kintone CDN. The libraries below need to be downloaded first and applied to the App.
The bulk download flow
The bulk download process from kintone will be as follows:
To download attachment files from kintone, you will first need to obtain the fileKey from the records using the Get Records API. The Download File API can then be used, using the fileKey as the parameter value.
Note that the steps "Get Records", "Create fileKey list" and "Create URLs" need to run asynchronously.
Explanation of the source code
The source code places the button for the bulk download on the Record List view. When the button is clicked, the getZipFile function is called.
getZipFile starts a promise chain, making the order of the later processes clearer and handling of asynchronous processes easier.
then() is used to pass on the object obtained from getAppRecords from promise to promise, and a list of fileKeys is created from this object.
How to Use
Save the App's settings, and update your App.
A button should appear on the Record List. Click the button to start running the process to download Attachment files as a Zip file.
- In this sample, only data of up to 100 records will be downloaded as a Zip file.
- The sample does not support Attachment fields placed in tables.
- FileSaver.js has restrictions on file sizes, depending on what browser is being used.
This article introduced a method for bulk downloading.
This sample can be further extended to support more records, and support files inside tables. For downloads that may take a long time to process, implement a Spinner using spin.js for better user experience.