Chrome extension integration with Google Drive - handling native Google document formats

I’m working on a Chrome web store application that needs to handle files from Google Drive. I’ve already configured the MIME types and file extensions for regular files like txt and pdf in the app console, and those work fine.

Now I’m stuck on two related issues. First, I want my app to also work with native Google Docs files (the ones created directly in Google Docs, not uploaded documents). I’m not sure what MIME type or extension settings I need for these.

Second question is about file conversion. Once I get my app to recognize and open Google Docs files, I need to be able to download them as PDF files using the Google Drive API. Is there a way to convert them during the download process?

Any help with either of these problems would be great. I’ve been searching through the documentation but haven’t found clear answers for Chrome extensions specifically.

just hit this same issue last month! use application/vnd.google-apps.document for the mime type - no file extension needed since it’s cloud-based. for pdf conversion, hit the export endpoint: /files/{fileId}/export?mimeType=application/pdf. works great but give it a second to process.

I faced a similar challenge while working on a Chrome extension for Google Drive. To manage native Google Docs files, you’ll need to include application/vnd.google-apps.document in your MIME type settings. This also applies to Google Sheets and Slides if you plan to support those formats as well.

Regarding the export to PDF, leverage the Drive API’s export feature by calling the export endpoint with application/pdf as the MIME type. It automatically handles the conversion on the server side. Remember to ensure that you include files.readonly scope in your API settings for it to function correctly. Just a tip—make sure to thoroughly test the exported PDFs, as they sometimes don’t match the original formatting in Google Docs.

To handle native Google Docs files, make sure to include the MIME type application/vnd.google-apps.document in your settings. If you also want to incorporate Google Sheets or Slides, remember to add their respective MIME types as well. For downloading documents as PDFs, utilize the Drive API’s export functionality with application/pdf as the MIME type for the export request. Additionally, ensure that your application has the necessary OAuth scope, typically https://www.googleapis.com/auth/drive.readonly, for this to work smoothly. Keep in mind that Google Docs does not have a standard file extension, so the focus will be primarily on using the correct MIME types.