【发布时间】:2016-06-15 09:08:05
【问题描述】:
我使用脚本将带有图像的文件夹上传到(父?)文件夹。当我这样做时,确实会以正确的方式创建文件夹结构。但是,当我第二次尝试时,它会在根目录中创建一个同名的新文件夹。
如何更改我的代码,以便有一个将添加图像文件夹的父文件夹?
目前:
- 第一次:
/root/persons/test test@test.com/(此文件夹内的图片) - 第二次新建地图:
/root/persons/test2 test2@test2.com/(此文件夹内的图片)
我想要:/root/persons/*(folders)/(此文件夹中的图片)
我的代码:
/* The script is deployed as a web app and renders the form */
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
// This is important as file upload fail in IFRAME Sandbox mode.
}
/* This function will process the submitted form */
function uploadFiles(form) {
try {
/* Name of the Drive folder where the files should be saved */
var dropbox = form.myName + " " + form.myEmail;
var folder, folders = DriveApp.getFoldersByName(dropbox);
/* Find the folder, create if the folder does not exist */
if (folders.hasNext()) {
folder = folders.next();
} else {
var firstLevelFolder = DriveApp.createFolder("Persons");
var folder = firstLevelFolder.createFolder(dropbox);
}
/* Get the file uploaded though the form as a blob */
var blob = form.myFile;
var file = folder.createFile(blob);
/* Set the file description as the name of the uploader */
file.setDescription("Uploaded by " + form.myName);
/* Return the download URL of the file once its on Google Drive */
return "File uploaded successfully " + file.getUrl();
} catch (error) {
/* If there's an error, show the error message */
return error.toString();
}
}
【问题讨论】:
标签: google-apps-script google-drive-api