'Save Gmail Attachments on Google drive - unknown file type

I looked for previous questions on this subject and found some posts from a few years ago. They don't exactly match my problem and when I try them I get more run errors than the script I am using. In my case, my script creates the files but they show up in my google drive as "unknown file" and can't be opened or previewed in Google drive. However, if I download the file to my pc, it opens and previews correctly and without any problem. How do I correct the "unknown" designation in my Google Drive?
I've tried a lot of possible solutions but either they get run time errors or I end up with an "empty" file.

Does anyone have any ideas on why this is happening or how to correct the unknown files attribute?

//pasted by Cooper as an example
function  putyourcodehere() {
  //this was posted via a ctrl-K
}


Solution 1:[1]

Save Attachment to a folder

function lfunko() {
  const query = 'subject:ThisIsATestMessage';
  Gmail.Users.Messages.list(gobj.globals.calendarid, { q: query }).messages.forEach(m => {
    GmailApp.getMessageById(m.id).getAttachments().forEach(a => {
      DriveApp.getFolderById(gobj.globals.testfolderid).createFile(a.copyBlob()).setName(a.getName());
    })
  })
}

gobj.globals is an object of global variables I use so that I don't have to redact them when used within answers that will be posted on SO. Just treat them as things you will have to replace with your own local variables. I used gobj.globals.calendarid because that's my email address which is what they want for the userid

Of course you will have to enable the Gmail API

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1