Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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
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:
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.
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?
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.
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!
Understood. We're tracking this as a feature request.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!