download multiple files or download into zip file

0
hi team ,in my application , when user selects the multiple checkbox then the single pdf will start downloading containing the data for all the checkboxes.  now i want  seperate pdf will download for the differernt checkboxes . how i can did this with java actions ? plz explain in brief .  Thanks in advance !!
asked
3 answers
1

you may need to store all these pdf file as filedocument in list, then use java action to download the list as zip files.

The lib you need to use are:

 

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.util.List;

import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream;

 

// input list object

private List<IMendixObject> fileList;

 

// the code to implement

ByteArrayOutputStream baos = new ByteArrayOutputStream();

ZipOutputStream zipOut = new ZipOutputStream(baos);

for (IMendixObject fileObj : fileList) {

   // Retrieve the name of the file

   String fileName = fileObj.getValue(getContext(), "Name").toString();

   // Create a new ZIP entry

   ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry);

   // Retrieve the content of the file

   InputStream fileContent = Core.getFileDocumentContent(getContext(), fileObj);

   // Write the content to the ZIP output stream

   byte[] bytes = new byte[1024];

   int length;

   while ((length = fileContent.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); }

   fileContent.close();

   zipOut.closeEntry(); }

 

   zipOut.close();

 

   // Convert ByteArrayOutputStream to InputStream

    return new ByteArrayInputStream(baos.toByteArray());

answered
1

Hi,

the common approach is to zip all files (there are several modules for zip handling available) and download the archive.

You can't download multiple files from a single microflow. It might work to loop over the downloads in a nanoflow.

regards, Fabian

answered
0

Or use a JavaScript action like I shared in below forum post to trigger the multi file download:

 

https://forum.mendix.com/link/space/studio-pro/questions/119569

answered