Multi-file download widget does not work.

2
Hi, I've tried the Multi-file-download widget to achieve multiple file downloads. However, it did not work with Mendix version 8 with the following client error. Is there a solution? obj.getGUID is not a function TypeError: obj.getGUID is not a function at http://localhost:8080/widgets/DownloadMultipleFiles/widget/DownloadMultipleFiles.js?637572003980422586:68:103 at Object.forEach (http://localhost:8080/mxclientsystem/mxui/mxui.js?637572003980422586:5:31063) at S.<computed>.E._startDownload (http://localhost:8080/widgets/DownloadMultipleFiles/widget/DownloadMultipleFiles.js?637572003980422586:61:23) at http://localhost:8080/mxclientsystem/mxui/mxui.js?637572003980422586:5:27280 at R (http://localhost:8080/mxclientsystem/mxui/mxui.js?637572003980422586:79:211864) at http://localhost:8080/mxclientsystem/mxui/mxui.js?637572003980422586:79:219042   solved on 2021-06-02 This error is caused by an implementation error on my part. The cause is that I was trying to download a file entity with empty contents (HasContents is False). It worked fine after I did an operation to create the content of the file, such as generating a file with Generate document.  
asked
2 answers
0

Hi Kouga,

I developed the multi-file download widget and will look into this issue, thank you for reporting. I will keep you posted and update the widget in the marketplace if necessary. 

Kind regards,

Allard

answered
0

I also needed multiple file download. For this I created a simple JavaScript action that can do the trick:

// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
import "mx-global";
import { Big } from "big.js";

// BEGIN EXTRA CODE
export function downloadFileWithDelay(fileDoc) {
	if (fileDoc.get("HasContents")) {
		// get file location on server
		console.dir(fileDoc);
		const url = "/file?guid=" + fileDoc.getGuid() + "&target=internal";
		const name = fileDoc.get("Name");
		const message = "file with url:" + url + " and name " + name;

		console.debug("found " + message);
		// create a dummy link and append to page.
		// trigger click on link to download document
		// remove link again
		const a = document.createElement('a');
		a.href = url;
		a.target = '_parent';
		// use a.download if available, it prevents plugins from opening
		if ('download' in a) {
			a.download = name;
			// Add a to the doc for click to work.
			(document.body || document.documentElement).appendChild(a);

			if (a.click) {
				console.debug("starting download "  + message);
				a.click(); // trigger a click to initiate the download
			}
			// delete the temporary link.
			a.parentNode.removeChild(a);
		}
	}	
}
// END EXTRA CODE

/**
 * A JavaScript action which facilitates a multiple file download. It needs a FileDocument list as input parameter and downloads the files. 
 * 
 * The code creates a link for every file which needs to be downloaded, automatically clicks the linking and this initiates the download of the file in the browser. After downloading the link is removed again from the DOM. For Internet Explorer a delay of 500 ms is added as that is needed for it to work in IE.
 * @param {MxObject[]} fileDocumentList
 * @returns {Promise.<void>}
 */
export async function JS_MultipleFileDownload(fileDocumentList) {
	// BEGIN USER CODE
	// iterate over file list fed from Studio Pro
	fileDocumentList.forEach(fileDoc => {
		
		if (window.document.documentMode) {
			// a timeout is necessary for IE, which will otherwise only download the first file.
			setTimeout(() => {
				downloadFileWithDelay(fileDoc);
			}, 500);
		} else {
			downloadFileWithDelay(fileDoc);
		}

		
	})
	// END USER CODE
}

 

answered