我不久前制作了一个简单的文件上传器,现在由于某种原因它停止了工作。点击上传文件后,会返回以下错误:
InternalError: Cannot find method createFile((class)).
这里的Code.gs:
function onInstall(e) {
onOpen(e);
}
function onOpen() {
// Add a menu with some items, some separators, and a sub-menu.
DocumentApp.getUi().createMenu('RC Publications')
.addItem('Upload File', 'upload')
.addToUi();
}
function upload() {
DocumentApp.getUi().showSidebar(
HtmlService
.createHtmlOutputFromFile('form.html')
.setTitle('Upload File')
.setWidth(350 /* pixels */));
}
function uploadFiles(form) {
try {
var folderId = "insert-drive-id-here";
var folder = DriveApp.getFolderById(folderId);
var blob = form.myFile;
var file = folder.createFile(blob);
return "File uploaded successfully. Use the following code in the form:<p /><p /> " + file.getId();
} catch (error) {
return error.toString();
}
}
这里是form.html:
<div>
<form id="myForm">
Use the following form to upload an image file for the RC Publications App.
<input type="file" name="myFile" id="fileUpload">
<input type="submit" value="Upload File"
onclick="this.value='Uploading...';
document.getElementById('fileUpload').disabled=true;
this.disabled=true;
google.script.run.withSuccessHandler(fileUploaded)
.uploadFiles(this.parentNode);
return false;">
</form>
<div id="output"></div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<style>
input { display:block; margin: 20px; }
</style>
</div>
我已经看到有其他类似问题的人Google Apps Script Cannot find method createFile((class)),但他们的问题使用了已弃用的UiService类,因此不能直接应用于此处。我的代码之前工作正常,并且由于某种原因现在停止工作...知道为什么会发生这种情况,或者如何解决它?
奇怪的是,当我将以下行添加到uploadFiles()时,错误变为&#34; undefined&#34;代替:
DocumentApp.getUi().alert("hi");
我认为最后一个是一个奇怪的错误......