XLSX from Gmail to Google Sheets: invalid mime type. Content type seems to be application/octet?

前端 未结 2 1921
小蘑菇
小蘑菇 2021-01-26 04:54

I\'m trying to import an xlsx file from a Gmail Attachment to Google Drive (as Google Sheet) using Google Apps Script. I\'ve tried using the Advanced Drive API in GAS, but doing

2条回答
  •  庸人自扰
    2021-01-26 05:54

    These

    parents: [{id: folderId}],
    mimeType: MimeType.GOOGLE_SHEETS
    

    refer to the input file. See docs here. You should skip these.

    This snippet worked for me with Google Drive API v2:

    function abc() {
      var mail = GmailApp.search("SEARCH_TERM")[0];
      var msg = mail.getMessages()[0];
      var blob = msg.getAttachments()[0];
      var file = {
        title: 'Converted Spreadsheet'
      };
      Drive.Files.insert(file, blob, {convert: true});
    }
    

提交回复
热议问题