Storing image in an entity example

0
Hello, I am trying to find an explanation or example of how you would use the Core.storeFileDocumentContent method to store an image in an entity. What would be the best way to go about doing this? The image is created during a java action that that uses a java charting library to generate it. What would be the best way to go about storing it in an entity? Thank you.
asked
2 answers
1

Monique,

The method storeFileDocumentContent needs the following parameters; IContext context, IMendixObject fileDocument, String fileName, InputStream inputStream So to store your created file you'll need to create or use a context, create a new filedocument (or pass it as an input parameter to your java action), set a filename and create an inputstream pointing to your created image. Then you can set the content for the filedocument.

answered
1

Here's a quick method that takes a FileDocument entity and an open Java File object and stores that file into the entity:

private void setFileInFileDocument(File f, IMendixObject fileDocument) 
{
    try {
        FileInputStream storeStream = new FileInputStream(f);
        Core.storeFileDocumentContent(this.getContext(), fileDocument, f.getName(), storeStream);
    } 
    catch (Exception e) {System.out.println(e);}
}
answered