メインコンテンツにスキップ

MimeTypeApp

This is a Google Apps Script library for converting files from various MIME types to a specified target MIME type. The library accepts both file IDs and blobs as input values.

AI Summary

MimeTypeApp

Google Apps Script library that converts Google Drive files from various MIME types to a specified target MIME type.

Target Users

Intermediate-to-advanced Google Apps Script developers who need to batch-convert diverse Drive files within their workflows.

Problems Solved

Determining and coding conversion routes between MIME types by manually checking Drive API importFormats/exportFormats is complex and time-consuming.

Tags

Main Features

1
Automatic route discovery

Fetches Drive API importFormats/exportFormats data and automatically builds the optimal conversion path from source to target MIME type.

2
Accepts File IDs and Blobs

Allows either Drive file IDs or blobs as input, offering flexible invocation for different scenarios.

3
Batch conversion & thumbnail retrieval

Supports converting multiple files in one call and provides thumbnail blobs via getThumbnails.

4
Usable as library or standalone

Can be installed via project key as a library or copied as a standalone class script.

Usage Examples

Convert a Markdown file to Google Docs

function convertMarkdownToGoogleDoc() {
  // Reference the library
  const m = MimeTypeApp;

  // ID of the Markdown file stored in Drive
  const mdFileId = '###MARKDOWN_FILE_ID###';

  // Conversion options
  const options = {
    mimeType: 'application/vnd.google-apps.document', // target MIME type
    folderId: 'root' // destination folder (optional)
  };

  // Run conversion
  const resultIds = m
    .setFileIds([mdFileId]) // set source file
    .getAs(options);        // get the converted file ID

  Logger.log(resultIds);    // log the new Google Doc ID
}

Executing this snippet converts the specified Markdown file into a Google Document and logs the resulting file ID.