0

I have a form that uploads a File to a SlingServlet. The SlingSerlvet receives the file and it tries to save the file in DAM using com.day.cq.dam.api.AssetManager.(i.e. Save file in DAM programmatically)

The problem arises with MIME types. The user may upload a pdf,xls, doc etc. so the Type is not fixed. I don't know what to set the MIME type as(see the third parameter xxx) assetMgr.createAsset(newFile, is,"xxx", true);

I tried "application/octet-stream" but CQ ignores the Type saying asset ignored.

Log:

27.11.2014 18:58:48.595 *INFO* [JobHandler: /etc/workflow/instances/2014-11-27/model_879500607401687:/content/dam/videojetdocuments/videojetdocuments/offerletters/Präsentation_Dominik_Suess.pdf/jcr:content/renditions/original] com.day.cq.dam.video.FFMpegThumbnailProcess execute: asset [/content/dam/videojetdocuments/videojetdocuments/offerletters/Präsentation_Dominik_Suess.pdf] is not of a video mime type, asset ignored.
27.11.2014 18:58:48.596 *INFO* [JobHandler: /etc/workflow/instances/2014-11-27/model_879500607401687:/content/dam/videojetdocuments/videojetdocuments/offerletters/Präsentation_Dominik_Suess.pdf/jcr:content/renditions/original] com.day.cq.dam.video.FFMpegTranscodeProcess execute: asset [/content/dam/videojetdocuments/videojetdocuments/offerletters/Präsentation_Dominik_Suess.pdf] is not of a video mime type, asset ignored.

I tried this using the following link

Is there any generic MIME Type for such type of Files?

Oliver
  • 6,152
  • 2
  • 42
  • 75

1 Answers1

1

You can use the Apache Sling MimeTypeService to compute the mimetype based on an incoming filename. See also http://sling.apache.org/documentation/bundles/mime-type-support-commons-mime.html

If you don't have the filename you'll need something like the Apache Tika Detector, which analyzes the binary to try to guess its mimetype. I don't know if CQ provides such a service out of the box, but if it doesn't you could integrate it yourself.

Edit:

API that checks the MIMEType based on Magic headers Link

Helpful link for understanding the above mentioned problem Link

Oliver
  • 6,152
  • 2
  • 42
  • 75
Bertrand Delacretaz
  • 6,100
  • 19
  • 24
  • I don't want to check MimeType with file name and extention that is lame. So I am trying open source API's that Check MimeType based on Magic Headers. Apache Tika is too huge and required a lot of other jars as well. – Oliver Nov 28 '14 at 09:46
  • It worked however I did not use Apache Tika due to its heavy dependencies. I used something called as MimeUtil. It checks the MimeType based on Magic Headers. Link in Answer. Great job Bertnard – Oliver Nov 28 '14 at 10:29
  • Thanks for the useful references! – Bertrand Delacretaz Nov 28 '14 at 14:46