Mime Type of a file

Hello. I need a way to get folderitem , better, from a file, its mime type.
THere is way without guessing It by the extension name ?
THanks
C

Have a go at Google for “list of mime types”.

Yes, that’s right, but how to match ?

Without being harsh… Google returns hundreds of links with command line tools for each OS to do exactly this. XOJO doesn’t contain a function to do it for you.

Yes exactly Dave:
For Osx and Linux:
file --mime-type filename

I don’t like to call shell commands from my softwares. Apple put some restriction for Store submission for software calling shel scripts ?
THanks
C

http://stackoverflow.com/questions/1029740/get-mime-type-from-filename-extension

Just create your own function with a list of such (using select case, passing the extension)… kind of like what the link above does.

Did the first few, so you can get an idea…

[code]Function getMimeType(fileExtension as text) As text

select case fileExtension.lowerCase.trim.replaceAll(".", “”)
case “323”
return “text/h323”
case “3g2”
return “video/3gpp2”
case “3gp”
return “video/3gpp”
case “3gp2”
return “video/3gpp2”
case “3gpp”
return “video/3gpp”
case “7z”
return “application/x-7z-compressed”
case “aa”
return “audio/audible”
case “aac”
return “audio/aac”
case “aaf”
return “application/octet-stream”
case “aax”
return “audio/vnd.audible.aax”
end select

End Function[/code]

Yes that is a solution. But I have not in mind this kind until there is the possibility the user change the file extension arbitrary.
So a file named goofy.pdf can be a jpeg or png image instead.
Thanks
C

As long as you don’t try to execute another program or to do thing forbidden by the sandbox, shell is quite fine. More than a dozen of my MAS apps use shell, and a couple of them are actually GUIs for command line.

[quote]Yes that is a solution. But I have not in mind this kind until there is the possibility the user change the file extension arbitrary.
So a file named goofy.pdf can be a jpeg or png image instead.
[/quote]

You will never be able to predict the kind of stupid things some users will come up with. Changing the extension will not only break your app, but all possibility to use the document with related programs. At one point, you cannot prevent a idiot from shooting himself in the foot.

Mac OS X itself has very little defences against that kind of manipulations. Except of course a warning signal from the finder.

You might try looking at the header of graphic files, or zip files with a binary stream, to make sure they are who they say they are. But that looks very much like overkill.