在谷歌驱动器中上传文件的脚本 - 遇到错误:发生意外错误

时间:2015-04-21 10:02:58

标签: file-upload google-apps-script google-sheets

我使用脚本将文档上传到Google电子表格,并自动将链接放入当前单元格。从昨天开始一切都很好,但从今天早上起我收到了这个通用错误: https://docs.google.com 遇到错误:发生意外错误

这是代码:

// upload document into google spreadsheet
// and put link to it into current cell

function onOpen(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var menuEntries = [];
  menuEntries.push({name: "Accedi al modulo per allegare un file...", functionName: "doGet"});
  ss.addMenu("Carica scheda di rilevazione dati...", menuEntries);
}

function doGet(e) {
  var app = UiApp.createApplication().setTitle("FORM per il caricamento della scheda di rilevazione dati");
  SpreadsheetApp.getActiveSpreadsheet().show(app);
  var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
  var formContent = app.createVerticalPanel();
  form.add(formContent);  
  formContent.add(app.createFileUpload().setName('thefile'));

  // these parameters need to be passed by form
  // in doPost() these cannot be found out anymore
  formContent.add(app.createHidden("activeCell", SpreadsheetApp.getActiveRange().getA1Notation()));
  formContent.add(app.createHidden("activeSheet", SpreadsheetApp.getActiveSheet().getName()));
  formContent.add(app.createHidden("activeSpreadsheet", SpreadsheetApp.getActiveSpreadsheet().getId()));
  formContent.add(app.createSubmitButton('Invia ed archivia scheda'));
  app.add(form);
  SpreadsheetApp.getActiveSpreadsheet().show(app);
  return app;
}

function doPost(e) {
  var app = UiApp.getActiveApplication();
  app.createLabel('sto salvando...');
  var fileBlob = e.parameter.thefile;
  var doc = DocsList.getFolderById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').createFile(fileBlob);
  var label = app.createLabel('file caricato con successo');

  // write value into current cell
  var value = 'hyperlink("' + doc.getUrl() + '";"' + doc.getName() + '")'
  var activeSpreadsheet = e.parameter.activeSpreadsheet;
  var activeSheet = e.parameter.activeSheet;
  var activeCell = e.parameter.activeCell;
  var label = app.createLabel('file memorizzato correttamente');
  app.add(label);
  SpreadsheetApp.openById(activeSpreadsheet).getSheetByName(activeSheet).getRange(activeCell).setFormula(value);
  app.close();
  return app;
}

1 个答案:

答案 0 :(得分:0)

根据您的问题

从昨天开始一切都很顺利,但从今天早上起我收到了这个一般错误:https://docs.google.com遇到错误:发生了意外错误

根据谷歌开发者的说法 page

enter image description here

所以,我认为问题可能在

  

var doc = DocsList.getFolderById('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')。createFile(fileBlob);

尝试使用 DriveApp 而不是 DocList more info