我成功地将一个文本文件上传到谷歌云端硬盘,并且我编写了一个成功地将文本翻译成猪拉丁语的方法。现在我正在尝试在 Google Drive 中创建一个新文档来输出翻译后的文本。但是我总是收到消息:“发生错误”,当我检查我的驱动器时,我只有原始上传的文本。
这是我的代码:
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload");
var formContent = app.createVerticalPanel();
formContent.add(app.createFileUpload().setName('thefile'));
formContent.add(app.createSubmitButton('submit'));
var form = app.createFormPanel();
form.add(formContent);
app.add(form);
return app;
}
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
var doc = DocsList.createFile(fileBlob);
var app = UiApp.getActiveApplication();
//Display a confirmation message
var label = app.createLabel('file uploaded successfully');
app.add(label);
return app;
var text = doc.getDataAsString();
Logger.log('I uploaded and my text is: ' + text);
MakeTranslationDoc(text);
}
function MakeTranslationDoc(passedText)
{
// Create a new Report
var newdoc = DocumentApp.create('Pig Latin Translation');
newdoc.appendParagraph(ParseText(passedText));
// Save and close the document
newdoc.saveAndClose();
}
function ParseText(myText)
{
...convert text to piglatin...
return results;
}
我应该怎么做才能从上传的文本成功创建新文档?