Hi all.
If you try to upload a "Thumbs.db" file (the files that Windows creates
automatically in the pictures folders) the file is considered as a Word
document and it happens many errors when it's indexed.
To fix that I use the following extension:
<extension
target="org.nuxeo.ecm.platform.mimetype.service.MimetypeRegistryService"
point="mimetype">
<mimetype normalized="application/octet-stream" binary="true"
iconPath="application.png">
<mimetypes>
<mimetype>application/octet-stream</mimetype>
</mimetypes>
<extensions>
<extension>db</extension>
</extensions>
</mimetype>
</extension>
Now, the file is upload as an application/octet-stream, but when the
file is created (or deleted) the former exception is thrown. The problem
seems to be located in the MimeMagic library, that returns the
"application/msword" mime type for these files. So I've redefined the
"getMimetypeFromBlob" method of the MimetypeRegistryService class:
public String getMimetypeFromBlob(Blob blob)
throws MimetypeNotFoundException, MimetypeDetectionException {
File file = null;
String filename= blob.getFilename();
if (filename.toLowerCase().endsWith(".db")) {
return "application/octet-stream";
}
try {
// make sure the blob can be read several times without
exhausting
// its
// binary source
if (!blob.isPersistent()) {
blob = blob.persist();
}
file = File.createTempFile("NXMimetypeBean", ".bin");
FileUtils.copyToFile(blob.getStream(), file);
return getMimetypeFromFile(file);
} catch (IOException e) {
throw new MimetypeDetectionException(e.getMessage(), e);
} finally {
if (file != null) {
file.delete();
}
}
}
In the previous code, if the extension of the file is ".db" the method
doesn't check the mime type of the file and returns
"application/octet-stream". This code works fine, but I think that it's
a dirty code. Is there another way to fix it? Maybe with the
configuration of the MimeMagic?
Regards.
--
Enrique Pérez Olivares.
Dpto I+D.
Yerbabuena Software.
[email protected]
http://www.yerbabuena.es
Tlf/Fax: 902 995 246
_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm
To unsubscribe, go to http://lists.nuxeo.com/mailman/options/ecm