我希望此代码填充用户上传到Google云端硬盘中设置文件夹的文件,而不是每次都创建一个新文件夹。我该怎么做?
请参见下面的现有代码:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html');
}
function uploadFiles(form) {
try {
var dropbox = form.myName + ", " + form.myBusiness;
var folder, folders = DriveApp.getFoldersByName(dropbox);
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
var blob = form.myFile;
var file = folder.createFile(blob);
file.setDescription("Uploaded by " + form.myName + ", " + form.myBusiness + ", " + form.details);
return "File uploaded successfully " + file.getUrl();
} catch (error) {
return error.toString();
}
}
答案 0 :(得分:1)
自己解决。将dropbox var更改为文件应该上传到的文件夹名称。该文件名在GDrive和代码中必须完全相同。示例:
var dropbox = "Example file name";
var folder, folders = DriveApp.getFoldersByName(dropbox);