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 this results in this error:
API call to drive.files.insert failed with error: Invalid mime type provided
I've figured out that the Gmail attachment is imported to Google Apps Script as application/octet instead of application/vnd.ms-excel, which I think is the problem. However, the attachment is an xlsx file and I don't see why that would be recognised as application/octet.
Keep in mind, I want to convert the XLSX to Google Sheets. Therefore I need the MimeType. Here's the code:
var mail = GmailApp.search("XXXXXXX")[0];
var msg = mail.getMessages()[0]
var attachment = msg.getAttachments()[0];
var blob =attachment
var name = attachment.getName();
var folderId = 'XXXXXX';
var file = {
title: 'Converted Spreadsheet',
parents: [{id: folderId}],
mimeType: MimeType.GOOGLE_SHEETS
};
file = Drive.Files.insert(file, blob, {convert: true})
Does anyone have an idea of how to fix the error or find another way to convert this XLSX to a sheet? Thanks!