Google脚本:下载网络图像并将其保存在特定的驱动器文件夹中 [英] Google script: Download web image and save it in a specific drive folder
问题描述
我需要使用GS下载图像并将其保存在特定的驱动器文件夹中. 我可以将图像保存在根文件夹中,但不能将其保存在特定文件夹中:
I need to download an image with GS and save it in a specific drive folder. I'm able to save the image in the root folder but i cannot save it in a specific folder:
function downloadFile(fileURL,folder) {
var fileName = "";
var fileSize = 0;
var response = UrlFetchApp.fetch(fileURL, {muteHttpExceptions: true});
var rc = response.getResponseCode();
if (rc == 200) {
var fileBlob = response.getBlob()
var folder = DriveApp.getFoldersByName(folder);
if (folder != null) {
var file = DriveApp.createFile(fileBlob);
fileName = file.getName();
fileSize = file.getSize();
}
}
var fileInfo = { "rc":rc, "fileName":fileName, "fileSize":fileSize };
return fileInfo;
}
问题:我要添加什么才能使用变量文件夹"?
Question: what have I to add to use the variable "folder"?
我发现了很多不再使用的"DocList"类示例
I found a lot of examples with "DocList" Class that is not in use anymore
非常感谢
推荐答案
好吧,我想GAS在开发其API(功能)方面取得了很大进展
对象Folder的createFile(blob)
将完成此工作:
https://developers.google.com/apps-script/reference/驱动器/文件夹#createfileblob
Well, I guess GAS has make a lot of progress on developing its API, the function
createFile(blob)
of an object Folder will do the job:
https://developers.google.com/apps-script/reference/drive/folder#createfileblob
// Create an image file in Google Drive using the Maps service.
var blob = Maps.newStaticMap().setCenter('76 9th Avenue, New York NY').getBlob();
DriveApp.getRootFolder().createFile(blob);
答案很晚了,但以防万一有人碰到这种情况.
It's quite late for the answer but just incase some one runs into the situation.
这篇关于Google脚本:下载网络图像并将其保存在特定的驱动器文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!