Google应用脚本:从Google网站的表单中删除我的驱动器中的文档

时间:2012-09-09 15:28:51

标签: google-apps-script

我使用以下代码为我的学生创建一种Dropbox。该表单嵌入在Google网站页面上。当文件在“dropbox”文件夹中发送时,它会自动转换为文本文件。我确实试过.doc,.xls和.pdf ...... 应该可以避免这个问题吗? 非常感谢 让保

var folderName = "Assignments-Spring-2011";

function doGet() {

  var app = UiApp.createApplication().setTitle("Upload Assignment");
  app.setHeight(180);
  var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
  var formContent = app.createGrid().resize(6,2);
  form.add(formContent);

  formContent.setWidget(1, 0, app.createLabel('Assignment Number:'));
  var assignmentNumberList = app.createListBox();
  assignmentNumberList.addItem("Assignment 1");
  assignmentNumberList.addItem("Assignment 2");
  assignmentNumberList.addItem("Assignment 3");
  assignmentNumberList.addItem("Assignment 4");
  assignmentNumberList.addItem("Assignment 5");
  assignmentNumberList.addItem("Assignment 6");
  assignmentNumberList.addItem("Assignment 7");
  assignmentNumberList.addItem("Assignment 8");

  formContent.setWidget(1, 1, assignmentNumberList.setName('assignmentNumber'));

  formContent.setWidget(3, 0, app.createLabel('Assignment File:'));
  formContent.setWidget(3, 1, app.createFileUpload().setName('thefile'));
  formContent.setWidget(5, 0, app.createSubmitButton('Submit Assignment!'));

  // thank you panel
  var panel = app.createSimplePanel().setVisible(false).setId("thankyouPanel");
  var label = app.createLabel("Thank you for submitting the         Assignment").setStyleAttribute("fontSize", "16px");
  panel.add(label);

  app.add(panel);
  app.add(form);

  return app;
}

function doPost(e) {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var name = Session.getActiveUser().getUserLoginId();
  var assignmentFile = e.parameter.file;
  var uploadBlob = Utilities.newBlob        (assignmentFile, "text/plain",e.parameter.assignmentNumber+"-"+name+"-"+e.parameter.thefile.name );
  var doc = DocsList.createFile(uploadBlob);
  // get assignment folder
  var folder = DocsList.getFolder(folderName);
  doc.addToFolder(folder);

  var app = UiApp.getActiveApplication();
  var form = app.getElementById("frm").setVisible(false);
  var panel = app.getElementById("thankyouPanel").setVisible(true);
  app.close();
  return app;
}

1 个答案:

答案 0 :(得分:3)

看起来你曾经使用的代码是故意将其限制为文本:

var uploadBlob = Utilities.newBlob        (assignmentFile, "text/plain",e.parameter.assignmentNumber+"-"+name+"-"+e.parameter.thefile.name );

简单地删除该行并重定向您的变量

var uploadBlob = e.parameter.file;

应该让你顺利。