Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Stuart T.'s avatar
Stuart T.
New member | Level 1
11 years ago

DBFile Mime Type?

Is there any way to get the mime-type of a DBFile? Ideally, it'd be nice to query from the DBFileInfo so I can know before I download it. But if that's not possible, can I get it from a file I've downloaded? I'm using the iOS Sync API

8 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    11 years ago

    The Sync SDK doesn't currently offer the mime type for DBFile, but I'll be sure to pass this along as a feature request.

    One thing you may want to do is maintain a mapping of file extension to type and use that against the returned file extension though. For example, we have a list of groupings here:

    https://www.dropbox.com/developers/reference/devguide

  • To add a little color here, what Greg suggests is all that Dropbox does anyway. We don't store any sort of MIME type with the file; we just look at the file extension. So there's no advantage to getting this information from Dropbox; just pick your favorite list (e.g. from a web server) and map the extensions yourself.

  • Stuart T.'s avatar
    Stuart T.
    New member | Level 1
    11 years ago

    So Dropbox determines the MIME type entirely by file extension? Is that ever a problem, because the file extension doesn't guarantee file type?

  • Yes, that's what Dropbox does. It's true that file extension doesn't guarantee file type. Can you think of something that does guarantee the file type?

  • Stuart T.'s avatar
    Stuart T.
    New member | Level 1
    11 years ago

    I suppose any solution is a lookup so maybe it doesn't guarantee, but previously we were using an iOS library called MagicKit which uses libmagic. However, I was hoping to get rid of it as it is causing some issues and appears to no longer be supported.
    https://github.com/aidansteele/MagicKit

  • Libmagic guesses based on the file contents. We're unlikely to take that approach... you could do something similar by just downloading the first portion of the file (a hundred bytes?), since most of the file type markers that this kind of library look for are located in the header of the file.

    What's the specific scenario for your app? Are you frequently seeing files with the "wrong" extensions? In any case, Dropbox itself isn't going to be able to help you here. We don't do any sniffing of file content to try to guess the MIME type.

  • Stuart T.'s avatar
    Stuart T.
    New member | Level 1
    11 years ago

    Steve,

    Well, I guess if I decide it's necessary to do any sniffing, I can do that on my own to verify file types, I guess I just assumed there would be occasional issues with relying on extension or if I file is missing an extension.

    But it would great if Dropbox is already doing a mapping a file extension to type that DBFileInfo still provided that information. Sure it could be done in the app but it's just additional logic that I would imagine is common in many apps.

    Thanks for your help Steve!

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!