How can I reset to default image in a Microflow?

I have an object inheriting from System.Image. I would like to include an action trigger with a Microflow that resets the uploaded image to the default image set in my project. How do I do that?
3 answers

I strongly recommend to use the default Mendix functionality. You have enough functionality to do what you want. The runtime will ensure that all objects and filesystem attributes will be handled in the correct way. I strongly recommend not to edit the System.FileDocument 'manually' using Java.


  • Just delete the System.Image object associated with your object.
  • Create a new System.Image and associate with your object. As long as you do not upload an image file the default image will be shown.

In case you want to replace the file associated with the System.Image object (instead of replacing the whole System.Image object), you have to use a Java action.

  • Create a Java action.
  • Use this method call: Core.storeFileDocumentContent(IContext context, IMendixObject fileDocument, inputStream).
  • You should put the System.Image object in the fileDocument param.
  • For the inputStream param it is the best to retrieve a System.Image object containing your default image. Use the Core.getFileDocumentContent(IMendixObject fileDocument) with that System.Image object as input to get the InputStream representing the image. This InputStream can be but in the inputStream param of the storeFileDocument call described above.

You can do it in this simple way:

  • Delete the current System.Image (or an inheriting) instance by the Object / Delete action in microflow.
  • Create a new object of type System.Image (or an inheriting type) and use that object in the rest of the flow.

Because the latest object have no content the default image will be shown by (for example) the image viewer widget.

If you don't want to remove the System.Image instance and create a new one System.Image instance, but only change the existing System.Image instance, you'll need JAVA code. With JAVA code the related file can be deleted from the file system. Furthermore you have to reset some attributes out the System.FileDocument object (FileName, Size, e.t.c.), but that can also be done with microflow.


Would simply adding a boolean 'is default image' do the trick (so that you can retrieve the image by Xpath)?