Hello, all happy new year 2020! I am trying to download a file from the INVOICE_DOCUMENT link (the file was previously uploaded there) in a new instance of the process. It turned out to save only the data on the file and its name and type separately. How can I combine these values on a js/html page or in Java code, so that the user can download the source file in different instances (through CaseInstance I call new instances of processes, when starting new instances I use the class to store the necessary information). Thank you for your attention!
A solution was found (without using the REST API, at the request of the task). The algorithm is as follows:
-
Get information about the file through the html form INVOICE_DOCUMENT
-
We transform the data into an array of bytes and read the name of the file with the extension.
-
We write the array to the file.
To generate the link, we use the copied file and, based on its data, create the download link in the INVOICE_DOCUMENT.
The solution is not the best, but still.
Hope it helps someone.
Get file and info:ByteArrayInputStream fileData = null; FileValueImpl fileMetadata = null; fileMetadata = (FileValueImpl)execution.getVariableLocalTyped("INVOICE_DOCUMENT"); fileData = (ByteArrayInputStream) execution.getVariable("INVOICE_DOCUMENT"); FileOutputStream fileOut = null; int size_file = fileData.available(); fileOut = new FileOutputStream(fileMetadata.getFilename()); byte[] data = new byte[fileData.available()]; fileData.read(data); fileOut.write(data);
Generation link:
FileValue typedFileValue = Variables
.fileValue(fileMetadata.getFilename())
.file(new File(fileMetadata.getFilename()))
.mimeType(fileMetadata.getMimeType())
.encoding(fileMetadata.getEncoding())
.create();
execution.setVariable("INVOICE_DOCUMENT", typedFileValue);
2 Likes