Determine file type in Ruby

There is a ruby binding to libmagic that does what you need. It is available as a gem named ruby-filemagic: gem install ruby-filemagic Require libmagic-dev. The documentation seems a little thin, but this should get you started: $ irb irb(main):001:0> require ‘filemagic’ => true irb(main):002:0> fm = FileMagic.new => #<FileMagic:0x7fd4afb0> irb(main):003:0> fm.file(‘foo.zip’) => “Zip archive … Read more

Determine MIME Type of NSData Loaded From a File

Perhaps you could download the file and use this to get the file’s MIME type. + (NSString*) mimeTypeForFileAtPath: (NSString *) path { if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { return nil; } // Borrowed from https://stackoverflow.com/questions/5996797/determine-mime-type-of-nsdata-loaded-from-a-file // itself, derived from https://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[path pathExtension], NULL); CFStringRef mimeType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType); CFRelease(UTI); if (!mimeType) … Read more

How do I determine the extension(s) associated with a MIME type in PHP?

Not built-in, but it’s not terribly hard to roll your own: function system_extension_mime_types() { # Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types. $out = array(); $file = fopen(‘/etc/mime.types’, ‘r’); while(($line = fgets($file)) !== false) { $line = trim(preg_replace(‘/#.*/’, ”, $line)); if(!$line) continue; $parts = preg_split(‘/\s+/’, $line); if(count($parts) … Read more

Path extension and MIME type of file in swift

If anyone wants to get the MimeType from the actual URL of the file this code worked for me: import MobileCoreServices func mimeTypeForPath(path: String) -> String { let url = NSURL(fileURLWithPath: path) let pathExtension = url.pathExtension if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() { if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() { return mimetype … Read more

How to set MIME type of application/vnd.apple.pkpass in order to share pass by link or email

Apache Add the following line to either: the .htaccess in the directory serving your .pkpass, or to the mime.types file, or to your appache httpd.conf or virtuatl server .conf file Then restart Apache (not required if adding to .htaccess) AddType application/vnd.apple.pkpass pkpass nginx Add the following line to your mime.types file and restart nginx application/vnd.apple.pkpass … Read more