Function getContentType() on JSFile

Hi all!

I’m doing some tests with JSFile, and I found out that getContentType() function is returning the content type only for a few file types…

I tested with .pdf, .txt, .html, several image files and .odt (OpenOffice Writer file) files, and the results are:

with .pdf returns “application/pdf” cool;
with .html returns “text/html” cool;
with image_files returns different types (jpeg, gif,…) cool;

… but:

with .txt returns null
with .odt returns null

This is the expected behaviour? I mean, it doesn´t recognize that file types?

Best regards,

Gerardo.

P.S.: I tested creating a image with the file too, but the behaviour is the same…

	var v_image =  plugins.images.getImage(v_file)
	var v_mimetype = v_image.getContentType()

I’m not sure, but I think you can change (or Servoy) in the activation.jar (found in the servoy-lib folder)

in that jar there is a meta-inf folder and there you will find a: mime_types.default

#
# A simple, old format, mime.types file
#
text/html		html htm HTML HTM
text/plain		txt text TXT TEXT
image/gif		gif GIF
image/ief		ief
image/jpeg		jpeg jpg jpe JPG
image/tiff		tiff tif
image/x-xwindowdump	xwd
application/postscript	ai eps ps
application/rtf		rtf
application/x-tex	tex
application/x-texinfo	texinfo texi
application/x-troff	t tr roff
audio/basic		au
audio/midi		midi mid
audio/x-aifc		aifc
audio/x-aiff            aif aiff
audio/x-mpeg		mpeg mpg
audio/x-wav             wav
video/mpeg		mpeg mpg mpe
video/quicktime		qt mov
video/x-msvideo		avi

Maybe Servoy or a 3th party plugin developer could look into these opensource projects:

http://www.rgagnon.com/javadetails/java-0487.html

http://lucene.apache.org/tika/
http://sourceforge.net/projects/jmimemagic/
http://sourceforge.net/projects/mime-util

Hi Harjo! Thanks for your reply!

Regarding your post, I have two ‘mime_types.default’ in my Servoy installation:

  • <servoy_dir>\application_server\lib; and
  • <servoy_dir>\developer\configuration.…\lib

But I think Servoy (or file plugin) is not using that files… In the both files I have txt suffix (in fact, in your image is that kind of file registered), but with a .txt file .getContentType() is returning null, and in the other hand, in my files there isn’t pdf or PDF (or something like that), however that kind of file is returning “application/pdf”

I’m doing some research on this…

Best regards,

Gerardo.

I have just “found out” the web.xml file at <servoy_dir>\application_server\server\conf!!!

There, pdf, txt, odt, … extensions are registered, and in WebClient the .getContentType() is returning the right value!!!

Due to this, is not Smart Client using this file???

Best regards,

Gerardo.

gerardo.gomez:
I have just “found out” the web.xml file at <servoy_dir>\application_server\server\conf!!!

Whatever is in this file is used by Tomcat for http clients (web clients), not smart client which uses RMI.

The smart client content type getting is done purely one bytes (the magic bytes)
Not on file name

Problem with Open Office formats is that those are just zip files… (and zip was one that we don’t return, if we did you would get application/zip)

So for those we have to check on names and extensions of the file name.

For a next version of servoy (maybe 5.1.x but not sure yet) i will see if we can also fall back to name guessing if we have the name for certain types.

It would be nice if there was a property or xml file somewhere on the internet where really many the extension->mime type where declared…
So that we can ship that one with the smart client

Something like this: http://www.w3schools.com/media/media_mimeref.asp

or http://www.webmaster-toolkit.com/mime-types.shtml

yes but those are html pages full of other stuff
Would be nice to have an easy to download property or xml file with just that content.

Lazy, huh? :D

jcompagner:
Would be nice to have an easy to download property or xml file with just that content.

Looking for something like that, I found a file used by Apache Sling project. File is here [mime.types] (“# Although created for httpd, this file is used by many software systems
# and has been placed in the public domain for unlimited redisribution.”).

Perhaps this helps!

Best regards,

Gerardo.

thats a pretty good one, its a pity that it isnt a real properties file so i have to scan for white space, but it is usable, thx!

Is this implemented yet (5.2.1)?

An Excel 97-2003 file returns application/msword

yes it is implemented in 5.2.x

But maybe in your case we just return to soon:

if (c1 == 0xD0 && c2 == 0xCF && c3 == 0x11 && c4 == 0xE0 && c5 == 0xA1 && c6 == 0xB1 && c7 == 0x1A && c8 == 0xE1)
{
return “application/msword”;
}

because we think we did found it but for this situation it is not really the case,
If you have a few samples (where you really know the file extension) that still give something wrong please make a case.

Noticed this for xls and ppt-files (office 97-2003). Case made: 319537