I use the following code to create a kind of dropbox for my students. The form is embedded on a google site page . When the file is sent in the "dropbox" folder, it is automatically converted in a text file. I did try with a .doc, .xls and .pdf... Should it be possible to avoid this problem ? Thanks a lot Jean-Paul
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;
}