Using a java action with Origin and Destination as FileDocument parameters:
InputStream in = Core.getFileDocumentContent(getContext(), __Origin);
File dest = Core.getFileDocumentContentAsFile(getContext(), __Destination);
OutputStream out = new FileOutputStream(dest);
org.apache.commons.io.IOUtils.copy(in, out);
in.close();
out.close();
Destination.setHasContents(true);
See an example of this in our Java API tutorial at https://world.mendix.com/display/howto25/Java+API+Tutorial
I had similar issues last week, trying to copy the contents of old FileDocuments into new ones.
To copy the document and link it to a new object, create that new object, as well as a System.FileDocument or specialization of it for the copied document. Set the association between the two objects, and copy any 'regular' attributes (such as Name) to the new Filedocument in the microflow. The slightly tricky part of course is the copying of binary data, for which Michel provided me a Java action. (I'm going by the assumption here that the document you want to copy is a System.Filedocument or specialization) This Java action should have two parameters, both FileDocuments; the original FileDocument and the one you are copying to. Code for the Java action in the user code area:
try {
InputStream in = Core.getFileDocumentContent(getContext(), __Origin);
File dest = Core.getFileDocumentContentAsFile(getContext(), __Destination);
OutputStream out = new FileOutputStream(dest);
org.apache.commons.io.IOUtils.copy(in, out);
in.close();
out.close();
Destination.setHasContents(true);
}
catch(Exception e) {
Core.getLogger(this.toString()).warn("Error while copying ", e);
throw e;
}
return true;
Names of the parameters here are Origin for the original document, and Destination for the new document you are copying to.
You can use the Misc.duplicatieFileDocument function which is provided in the community commons module.