Ok the complete solution
public static Boolean duplicateImage(IContext context, IMendixObject toClone, IMendixObject target) throws Exception
{
if (toClone == null || target == null)
throw new Exception("No file to clone or to clone into provided");
MendixBoolean hasContents = (MendixBoolean) toClone.getMember(context, FileDocument.MemberNames.HasContents.toString());
if (!hasContents.getValue(context))
return false;
InputStream inputStream = Core.getImage(context, toClone, false);
Core.storeImageDocumentContent(context, target, inputStream, 200, 200);
return true;
}
Invoke from java action
// BEGIN USER CODE
return Misc.duplicateImage(this.getContext(), __fileToClone, __cloneTarget);
// END USER CODE
Easily done using this piece of code:
Core.storeImageDocumentContent(context, imageDocument, inputStream, thumbnailWidth, thumbnailHeight);
You can open the CommunityUtils.Misc, copy the duplicateFileDocument and replace line 62 with the above (make sure to fill in the actual parameters) and create a new Java action like the filedocument one, only it receives an Image and calls on your new 'duplicateImageDocument'.
Edit: Oh btw, you also might want to switch the inputstream to the image variety, but this should be easy to find using Eclipse with Core.get + <ctrl+space> and using the autosuggestions.