似乎这应该更容易。但不可否认,我不了解 blob。
function doGet(e) {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel().setId('panel');
var fileUpload = app.createFileUpload().setName('theFile').setId('theFile');
var handler = app.createServerChangeHandler('uploadfile');
handler.addCallbackElement(panel);
fileUpload.addChangeHandler(handler);
panel.add(fileUpload);
app.add(panel);
return app;
}
function uploadfile(e)
{
// data returned which can be used to create a blob
// assuming mime-type to be a text file in this example
var fileBlob = Utilities.newBlob(e.parameter.thefile, "text/plain","file.txt" );
// Create a new file
var doc = DocumentApp.create('Uploaded Text File');
doc.appendParagraph(fileBlob.getDataAsString());
// Save and close the document
doc.saveAndClose();
//var doc = DocsList.createFile(fileBlob.getDataAsString());
var app = UiApp.getActiveApplication();
app.getElementById('panel').add(app.createLabel('File Uploaded successfully'));
return app;
}
当我尝试使用此 Google Apps 脚本代码上传文件时,我不断收到未定义的返回。我要做的就是将文本文件上传到我的 Google Drive。
我应该怎么做才能修复此代码?还是有更好的方法来做到这一点?