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
Ok. So I managed to figure this out so just updating.
Apparently the contentType 'pdf' was causing the problem. If I do a att[0].setContentType('application/pdf')
before trying to save the file, then the code works as expected.