Question

I am making a google script with some very basic functionality. There are errors however, that I do not understand. The code below works. The HTML sample is from the documentation at

https://developers.google.com/apps-script/reference/drive/drive-app#createFile(String,String)

function make50 () {
  var folder = DocsList.createFolder("NewLogFolder3");
  folder.createFile('New HTML File', '<b>Hello, world!</b>', MimeType.HTML);

  DriveApp.createFile("file", '', MimeType.GOOGLE_DOCS);
}

Since the above works and the documentation for folder.createFile is the same as for driveApp.createFile,

https://developers.google.com/apps-script/reference/drive/folder#createFile(String,String,String)

Why can't I do the following?

folder.createFile('new file', '', MimeType.GOOGLE_DOCS);

When I try to do this, I get

Invalid mime type. (line 42, file "Code")

Was it helpful?

Solution

Use DocumentApp.create('file name') to create a Google Doc.

You can't change the MimeType to a Google Doc through DriveApp.createFile.

OTHER TIPS

The problem as I understand it is that I mixed old and new code.

The DocsList class that I was using to create the folder is something I got from old StackOverflow posts.

Using DriveApp instead of DocsList, it works as I expected.

Odd thing is this used to work. I just came back to try a script I know worked in the past. It now throws an invalid mime type error... odd thing is it does work with the kix file type

folder.createFile(filename, "", 'application/vnd.google-apps.document');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top