Thanks Robert for providing information on this. How about modifying the
existing SlingTikaDetector itself and adding a mechanism in it to resort to
inputstream based mime-type detection if name based detection draws a
null. inputstream based mime-type detection would only come into play when
nothing can be inferred from the name and hence would be avoided in most of
the cases as files are usually named correctly based on their contents.

The related impact would be that any file whose name did not indicate its
mime-type will now get its mime-type set based on it contents unlike
application/octet-stream as it happens currently by default.

Regards
Satya Deep

On Mon, May 4, 2015 at 3:04 PM, Robert Munteanu <[email protected]> wrote:

> Hi,
>
> On Fri, May 1, 2015 at 8:22 AM, Satya Deep Maheshwari
> <[email protected]> wrote:
> > Hi
> >
> > I am facing a problem with the mime type detection of a file. While
> > debugging, I see that SlingTikaDetector.detect method is used for
> detecting
> > the mime type of my file. See [1]. This method just seems to rely on the
> > name of the file for detecting its mime type. Even though its passed an
> > inpuststream of the file, it does not seem to use it for mime type
> > detection. So if my file name is something like xyz.tmp, it detects its
> > mime type as application/octet-stream (the default) while it may actually
> > be a png file. This is a common scenario with webdav clients wherein
> > temporary files get created with such names while being edited. What
> should
> > be done at sling level to detect the mime type correctly for a file,
> > irrespective of its name?
>
> Following the discussions at SLING-1059 [1] and SLING-255 [2] I can
> infer that we more or less opted out of the 'heavy-weight' approach of
> actually parsing the input stream. Not sure if we want to revisit that
> TBH. At any rate, our MimeTypeService does not have an API for getting
> the file content based on the input stream.
>
> I think though there's a way around it, but only at the code level.
> The org.apache.sling.jcr.webdav.impl.helper.SlingResourceConfig class
> hardcodes the Detector implementation to be a SlingTikaDetector.
>
> I think it is worthwile to raise a Jira issue for this and it would
> definitely expedite the fix if you're willing to submit a patch / pull
> request. I think it can be as simple as adding a @Reference to a Tika
> Detector to the SlingWebDavServlet and then passing that to the
> SlingServletConfig.
>
> Cheers,
>
> Robert
>
> [1]: https://issues.apache.org/jira/browse/SLING-1059
> [2]: https://issues.apache.org/jira/browse/SLING-255
>
> >
> > Regards
> > Satya Deep
> >
> > [1] -
> >
> https://github.com/apache/sling/blob/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
>

Reply via email to