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
}
↧