FileDocument dropzone to image entity

Hello, We use dropzone to upload filedocuments. But some files are images (we can see by attribute Mime-type) How can I save these images as “image” entity?   Kind regards, Steven Keersmaekers
1 answers

Hi Steven,

What you can do, is initially save everything as File Document, but after that do some processing. 

First check the file type (as you already seem to do), then in case of images, extract the contents of the document (for example by decoding it into Base64. After that write the contents to an image entity.


Another way you could try is using the ‘Clone’ function from CommunityCommons. The documentation states: 

Clones objects

- Source: the original object to copy
- Target: the object to copy it into (should be of the same type, or a specialization)
- includeAssociations: whether to clone associations. 

If associated objects need to be cloned as well, use deepClone, this function only copies the references, not the reffered objects. Target is not committed automatically.

Since Image is a specialization of FileDocument, this could work.