Determining MIME types

  • Hey folks,
    I'm wondering if anyone knows of any ways to calculate the MIME type
    of a URL (either a local file or out on the internet)?

    Thanks,
    Matthew Delves
  • On Jan 18, 2008, at 5:14 PM, Matthew Delves wrote:

    > Hey folks,
    > I'm wondering if anyone knows of any ways to calculate the MIME type
    > of a URL (either a local file or out on the internet)?

    Take a look at the Uniform Type Identifier system and its
    documentation, <http://developer.apple.com/documentation/Carbon/Conceptual/understanding_ut
    is/
    >.

    If you (simply) extract the extension from the end of a filename, you
    can get its UTI and then turn that in to a MIME type.

    -> jp
  • On Jan 18, 2008, at 5:28 PM, Jim Puls wrote:

    > If you (simply) extract the extension from the end of a filename,
    > you can get its UTI and then turn that in to a MIME type.

    I was just about to suggest the same resource. I only have a couple of
    things to add:

    * Keep in mind that the mappings provided by that API is incomplete,
    even for popular / common file types.

    * IIRC (and this is clearly not my area of expertise) if you're
    downloading something over HTTP (and probably other protocols too) the
    server can provide a MIME type that differs from the one you would
    expect from just looking at the file name suffix. There might not even
    be a file name suffix, but the server can still provide a MIME type.

    j o a r
  • On 19/01/2008, at 12:35 PM, j o a r wrote:

    >
    > On Jan 18, 2008, at 5:28 PM, Jim Puls wrote:
    >
    >> If you (simply) extract the extension from the end of a filename,
    >> you can get its UTI and then turn that in to a MIME type.
    >
    >
    > I was just about to suggest the same resource. I only have a couple
    > of things to add:
    >
    > * Keep in mind that the mappings provided by that API is incomplete,
    > even for popular / common file types.
    >

    Still, something is better than nothing.

    > * IIRC (and this is clearly not my area of expertise) if you're
    > downloading something over HTTP (and probably other protocols too)
    > the server can provide a MIME type that differs from the one you
    > would expect from just looking at the file name suffix. There might
    > not even be a file name suffix, but the server can still provide a
    > MIME type.

    NSURLResponse provides a method for retrieving the MIME type, though
    what I would prefer is something which can be calculated from the
    filename.

    I have managed to get the UTI from the file extension, though unsure
    about how to get the MIME type from the UTI.

    Thanks,
    Matthew Delves
  • On Jan 18, 2008, at 10:36 PM, Matthew Delves wrote:

    > I have managed to get the UTI from the file extension, though unsure
    > about how to get the MIME type from the UTI.

    Something like this:

    CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (theUTI,
    kUTTagClassMIMEType);

    j o a r
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today