Description
While I was setting up a HTML5 video player, I notice that .mp4 files uploaded to the assets have the wrong mime type ("video/quicktime" insteaed of "video/mp4"). To fix it, I added a file "mime-types.properties" with the following content.
mp4=video/mp4
webm=video/webm
ogv=video/ogg
but it did not work. So I did a little bit of debugging to see whether it was being picked up by "eu.medsea.mimeutil.detector.ExtensionMimeDetector". It turned out that it was being picked up and the extensions were being added but it did not do the trick because when the MimeUtil is being called at "org.hippoecm.frontend.plugins.yui.upload.MagicMimeTypeFileItem.resolveMimeType (line 68)"
65 private String resolveMimeType(FileItem fileItem) {
66 Collection<?> mimeTypes = null;
67 if(fileItem instanceof DiskFileItem && !fileItem.isInMemory())
else {
the value of "(DiskFileItem)fileItem).getStoreLocation()" is a temp file with extension .tmp.
So MimeUtil does try to find the MimeType based on the file extension but to no avail (since the file extension is always .tmp) and then resorts to guessing the MimeType based on the content of the file which is not always accurate.
So I fixed this problem by replacing the following lines in the class "org.hippoecm.frontend.plugins.yui.upload.MagicMimeTypeFileItem"
private String resolveMimeType(FileItem fileItem) {
Collection<?> mimeTypes = null;
if(fileItem instanceof DiskFileItem && !fileItem.isInMemory())
else {
InputStream inputStream = null;
try
catch (IOException e)
{ log.warn("IOException prevented retrieval of mimetype; using default", e); } finally {
try {
if (inputStream != null)
} catch (IOException e)
{ log.warn("Could not close inputstream after retrieving mimetype", e); } }
}
....
with
private String resolveMimeType(FileItem fileItem) {
Collection<?> mimeTypes = null;
if (StringUtils.isNotBlank(fileItem.getName()))
if (mimeTypes == null) {
if(fileItem instanceof DiskFileItem && !fileItem.isInMemory())
else {
InputStream inputStream = null;
try
catch (IOException e)
{ log.warn("IOException prevented retrieval of mimetype; using default", e); } finally {
try {
if (inputStream != null)
} catch (IOException e)
{ log.warn("Could not close inputstream after retrieving mimetype", e); } }
}
}
So now it first tries to resolved the mimetype based on the extension of original file and if that is unsuccessful it resolves the type based on the content of the inputstream.
Attachments
Issue Links
- relates to
-
CMS-8510 Wrong mime type determination for assets
- Closed