How can I copy an object inheriting from image?

I have two objects inheriting from image named A & B. I've created a copy MF where I copy all information of object A to B. How can I copy the image from A to B (and all its required information) making sure that when I delete the image for object A the object is not deleted for object B?
1 answers

You have to use a Java action. Please note that a System.Image object differs from a System.FileDocument (from which it derives). To copy the file of a System.FileDocument instance, follow the steps written by Johan den Haan.

However, uploading an image has the following advantage over uploading a System.FileDocument. While uploading an image, also a thumbnail is created from the image. So if you copy the image, also a new thumbnail must be created. Therefore, don’t use the method Core.storeFileDocumentContent(...) to store a System.Image file! In case of a System.Image file, use the following steps:

  • Create a Java action.
  • Call the method: Core.getFileDocumentContent(IMendixObject fileDocument) with object A as argument. This method returns an InputStream.
  • Then call this method: Core.storeImageDocumentContent(IContext context, IMendixObject imageDocument, InputStream inputStream, int thumbnailWidth, int thumbnailHeight). Put object B in the imageDocument parameter and put the returned InputStream from the previous method call in the inputstream parameter of this method. Put the width and height you want for the thumbnail in the last two parameters.

After executing your microflow and this Java action, A and B are full copies of each other and deleting object A does not influence anything of object B.