MIME Types in Google Drive

You can find the MIME type of any file in your Google Drive using getMimeType() method as long as the MIME is support by Google Drive. Your script can then easily figure out the actual type (more user friendly) of the file or document using the following getFileType method. For instance, Google Spreadsheet for application/vnd.google-apps.spreadsheet and so on.

var mimeType = file.getMimeType();
var fileType = getFileType(mimeType);

function getFileType(mimeType) {
  var filetype = '';

  switch (mimeType) {
    case MimeType.GOOGLE_APPS_SCRIPT:
      filetype = 'Google Apps Script';
      break;
    case MimeType.GOOGLE_DRAWINGS:
      filetype = 'Google Drawings';
      break;
    case MimeType.GOOGLE_DOCS:
      filetype = 'Google Docs';
      break;
    case MimeType.GOOGLE_FORMS:
      filetype = 'Google Forms';
      break;
    case MimeType.GOOGLE_SHEETS:
      filetype = 'Google Sheets';
      break;
    case MimeType.GOOGLE_SLIDES:
      filetype = 'Google Slides';
      break;
    case MimeType.FOLDER:
      filetype = 'Google Drive folder';
      break;
    case MimeType.BMP:
      filetype = 'BMP';
      break;
    case MimeType.GIF:
      filetype = 'GIF';
      break;
    case MimeType.JPEG:
      filetype = 'JPEG';
      break;
    case MimeType.PNG:
      filetype = 'PNG';
      break;
    case MimeType.SVG:
      filetype = 'SVG';
      break;
    case MimeType.PDF:
      filetype = 'PDF';
      break;
    case MimeType.CSS:
      filetype = 'CSS';
      break;
    case MimeType.CSV:
      filetype = 'CSV';
      break;
    case MimeType.HTML:
      filetype = 'HTML';
      break;
    case MimeType.JAVASCRIPT:
      filetype = 'JavaScript';
      break;
    case MimeType.PLAIN_TEXT:
      filetype = 'Plain Text';
      break;
    case MimeType.RTF:
      filetype = 'Rich Text';
      break;
    case MimeType.OPENDOCUMENT_GRAPHICS:
      filetype = 'OpenDocument Graphics';
      break;
    case MimeType.OPENDOCUMENT_PRESENTATION:
      filetype = 'OpenDocument Presentation';
      break;
    case MimeType.OPENDOCUMENT_SPREADSHEET:
      filetype = 'OpenDocument Spreadsheet';
      break;
    case MimeType.OPENDOCUMENT_TEXT:
      filetype = 'OpenDocument Word';
      break;
    case MimeType.MICROSOFT_EXCEL:
      filetype = 'Microsoft Excel';
      break;
    case MimeType.MICROSOFT_EXCEL_LEGACY:
      filetype = 'Microsoft Excel';
      break;
    case MimeType.MICROSOFT_POWERPOINT:
      filetype = 'Microsoft PowerPoint';
      break;
    case MimeType.MICROSOFT_POWERPOINT_LEGACY:
      filetype = 'Microsoft PowerPoint';
      break;
    case MimeType.MICROSOFT_WORD:
      filetype = 'Microsoft Word';
      break;
    case MimeType.MICROSOFT_WORD_LEGACY:
      filetype = 'Microsoft Word';
      break;
    case MimeType.ZIP:
      filetype = 'ZIP';
      break;
    default:
      filetype = 'Unknown';
  }

  return filetype;
}
Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

0

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.