Quantcast
Channel: Mendix Forum Questions
Viewing all articles
Browse latest Browse all 83469

How to create a ZIP file WITHOUT using a temp file, but fully using our File storage?

$
0
0
Hi all! I have a Java action to create a ZIP which works really fine. But there is 1 limitation, I have to create a temp file to prepare the ZIP before saving it in my regular file storage. And when I create a big zip (>4GB) there is not enough disk space (in the temp folder) and my application crashes. Here my source code for the Java action. Is there any way to initialize a ZipOutputStream without creating a temp file, but using a file from our file storage? public IMendixObject executeAction() throws Exception { // BEGIN USER CODE File tempZipFile = File.createTempFile("zipfile", "temp"); ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(tempZipFile)); InputStream inputStream = Core.getFileDocumentContent(getContext(), fileToZip); String fileName = fileToZip.getValue(getContext(), "Name"); if (fileName == null || fileName.isEmpty()) { fileName = "document.pdf"; } ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = inputStream.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); } inputStream.close(); zipOut.close(); InputStream zipInputStream = new FileInputStream(tempZipFile); IMendixObject finalZipDoc = Core.instantiate(getContext(), finalZip); Core.storeFileDocumentContent(getContext(), finalZipDoc, zipInputStream); zipInputStream.close(); tempZipFile.delete(); return finalZipDoc; // END USER CODE }

Viewing all articles
Browse latest Browse all 83469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>