First time posting, so please be gentle. I'm using bits of code from: https://www.splitbrain.org/blog/2017-01/30-save_gmail_attachments_to_google_drive https://ctrlq.org/code/19053-send-to-google-drive
I'm trying to save PDF attachments from Gmail directly to Google drive. I'm getting an Invalid Argument error when trying to save the file in the last line of code below. I have a loop to go through message threads and then within that loop, this is the code that is saving the attachments:
var message = threads[x].getMessages()[0];
var saveFolder = getFolder(driveFolderID,message);//this is valid folder
var att = message.getAttachments();
Logger.log(att[0].getContentType()); //this returns 'pdf'
file = saveFolder.createFile(att[0]);
Anyone know what I'm doing wrong, or where to look next?
Thanks
"some string data"most certainly is not the appropriate content for a PDF - just naming the file with an extension does not make it that kind of file. You might consider casting explicitly from the classGmailAttachmentto the actual bytes of the attachment (getBytes) or to theBlobtype viagetBlob. Or if you've tried that already, make sure you're asking a good question. - tehhowch