# Function getContentType() on JSFile

**URL:** <https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109>\
**Category:** Classic Servoy\
**Created:** [April 27, 2010, 11:57am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109 "2010-04-27T11:57:12Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerardo.gomez](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gerardo.gomez](https://forum.servoy.com/u/gerardo.gomez)\
**Post date:** [April 27, 2010, 11:57am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/1 "2010-04-27T11:57:12Z")

</div>

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…

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

```

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [April 27, 2010, 12:13pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/2 "2010-04-27T12:13:21Z")

</div>

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

```auto
#
# 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://www.rgagnon.com/javadetails/java-0487.html)

[http://lucene.apache.org/tika/](http://lucene.apache.org/tika/)  
[http://sourceforge.net/projects/jmimemagic/](http://sourceforge.net/projects/jmimemagic/)  
[http://sourceforge.net/projects/mime-util](http://sourceforge.net/projects/mime-util)

---

<div class="post-metadata">

**Author:** ![gerardo.gomez](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gerardo.gomez](https://forum.servoy.com/u/gerardo.gomez)\
**Post date:** [April 28, 2010, 6:55am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/3 "2010-04-28T06:55:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gerardo.gomez](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gerardo.gomez](https://forum.servoy.com/u/gerardo.gomez)\
**Post date:** [April 28, 2010, 7:32am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/4 "2010-04-28T07:32:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [April 28, 2010, 12:53pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/5 "2010-04-28T12:53:02Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 28, 2010, 3:51pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/6 "2010-04-28T15:51:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 28, 2010, 3:56pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/7 "2010-04-28T15:56:04Z")

</div>

Something like this: [http://www.w3schools.com/media/media\_mimeref.asp](http://www.w3schools.com/media/media_mimeref.asp)

or [http://www.webmaster-toolkit.com/mime-types.shtml](http://www.webmaster-toolkit.com/mime-types.shtml)

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 29, 2010, 7:19am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/8 "2010-04-29T07:19:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [April 29, 2010, 7:47am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/9 "2010-04-29T07:47:26Z")

</div>

Lazy, huh? ![:D]( "Very Happy")

---

<div class="post-metadata">

**Author:** ![gerardo.gomez](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gerardo.gomez](https://forum.servoy.com/u/gerardo.gomez)\
**Post date:** [April 29, 2010, 9:38am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/10 "2010-04-29T09:38:14Z")

</div>

> 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](http://sling.apache.org/site/mime-type-support-commonsmime.html). File is here [[mime.types](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/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.

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [April 29, 2010, 9:41am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/11 "2010-04-29T09:41:17Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![michel](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@michel](https://forum.servoy.com/u/michel)\
**Post date:** [September 13, 2010, 2:59pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/12 "2010-09-13T14:59:07Z")

</div>

Is this implemented yet (5.2.1)?

An Excel 97-2003 file returns application/msword

---

<div class="post-metadata">

**Author:** ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)\
**Post date:** [September 13, 2010, 3:21pm UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/13 "2010-09-13T15:21:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![michel](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@michel](https://forum.servoy.com/u/michel)\
**Post date:** [September 14, 2010, 9:22am UTC](https://forum.servoy.com/t/function-getcontenttype-on-jsfile/12109/14 "2010-09-14T09:22:06Z")

</div>

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