1
votes

In Google Apps Script I am trying to create file with specified mime type. Creating file works but mime type is always 'application/vnd.google-apps.document'.

var file = {
  'title': 'file.gs',
  'mimeType': 'application/vnd.google-apps.script',
  'parents': [{
    'id': folder.getId()
  }]
};
var fileGsContentBlob = Utilities.newBlob(fileGsContent);
var derp = Drive.Files.insert(file, calendarGsContentBlob);
return derp.mimeType; // returns always application/vnd.google-apps.document
2

2 Answers

0
votes

I've been doing with Utilities.newBlob(byteCharacters, type);, here the functioning code acepting a base64Data as input, the name of the new file and the id of the folder to put it, you could modify it to accept a blob:

function uploadArquivoParaDrive(base64Data, nomeArq, idPasta) {
  try{
    var splitBase = base64Data.split(','),
        type = splitBase[0].split(';')[0].replace('data:','');

    var byteCharacters = Utilities.base64Decode(splitBase[1]);
    var ss = Utilities.newBlob(byteCharacters, type);
    ss.setName(nomeArq);

    var file = DriveApp.getFolderById(idPasta).createFile(ss);

    return file.getName();
  }catch(e){
    return 'Erro: ' + e.toString();
  }
}
0
votes

Do you want to create Google Apps Script files?

It is done in a special way described here.

https://developers.google.com/apps-script/import-export?hl=en