Fetching an image from attachments

2
I have a problem, just looking for ways out. Earlier on in development I had an option of uploading an image and another one to upload any other file like videos, document files and audio files. I am just thinking aloud, I want to be able to upload images as attachments but be in a position to display them. Is that possible? If it is, How?
asked
2 answers
1

To copy an Attachment into an image you need to create a java action.

Just like to Duplicate image of the Community commons

With the following function you can copy the file into a Image

// BEGIN USER CODE
        return this.copyFileToImage(this.getContext(), __fileToClone, __cloneTarget, thumbWidth.intValue(), thumbHeight.intValue());
        // END USER CODE

// BEGIN EXTRA CODE

    private Boolean copyFileToImage(IContext context, IMendixObject toClone, IMendixObject target, int thumbWidth, int thumbHeight) 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.getFileDocumentContent(context, toClone); 

          Core.storeImageDocumentContent(context, target, inputStream, thumbWidth, thumbHeight);

          return true;
    }
    // END EXTRA CODE
answered
0

Eugene

To display an image on a web form - use the image viewer widget, which is one of the 'native' widgets in Mendix. Alternatively, there are a number of widgets in the appstore that will enable you to display (and edit) these images. One that I like is the image carousel which lets you flip through a collection of pictures.

To display a file (like a pdf), you can use the Document Viewer widget from the appstore. This will show the document inside of an embedded frame in your web form. This widget will also display images.

Have fun,

Mike

answered