How to return image mendix object in java action

0
Hi, I have created one java action which take input as image and compress this image. But I am trying to return this compressed image object in my java action. Below is the screenshot:   Currently I am storing compressed image at local machine folder path as highlighted in screenshot, But I want to return this image as CompressedImage mendix object to the microflow. how can I set compressed image to this..CompressedImage mendix object?
asked
3 answers
3

Analogly to reading an image you can also write the image.
Use Core.storeFileDocumentContent  https://apidocs.rnd.mendix.com/8/runtime/com/mendix/core/Core.html#storeFileDocumentContent(com.mendix.systemwideinterfaces.core.IContext,com.mendix.systemwideinterfaces.core.IMendixObject,java.io.InputStream)
Hope this helps,

Andre

answered
0

Answer to the comment using the fileoutputstream in pseudo code:

FileOutputStream fos = null;
File file;
       try {
      file = new File("C:/myfile.txt");
	  fos = new FileOutputStream(file);
	  
		//NOW USE THE FileOutputStream HERE TO WRITE THE FILE/IMAGE
         
       } 
       catch (IOException ioe) {
	  ioe.printStackTrace();
       } 
       finally {
	  try {
	     if (fos != null) 
	     {
		 fos.close();
	     }
          } 
	  catch (IOException ioe) {
	     System.out.println("Error in closing the Stream");
	  }
       }
 

 

answered
0

Hello Samarth Jadhav,

Use this below code to get file in object

FileInputStream fis = new FileInputStream(compressedImage1);
Core.storeFileDocumentContent(getContext(), OriginalImage.getMendixObject(), fis);

 

After calling javaaction commit the input file object which passed in javaaction.

 

Thanks.

answered