我可以从谷歌应用程序脚本生成的 URL 链接下载文件吗 [英] Can I download file from URL link generated by google apps script

查看:15
本文介绍了我可以从谷歌应用程序脚本生成的 URL 链接下载文件吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我短期学习 google-apps-script.我想通过从存储在电子表格中的数据生成的 url 从远程站点下载文件.

Please help I'm learning google-apps-script for short time. I want to download file from remote site by url generating from data that stores in my spreadsheet.

例如,我有 2 个参数:

for example, i have 2 paremeters:

Cell1 = val1, val2, ... valN
Cell2 = val21, val22, ...  val2N

我将单元格数据中的字符串拆分为数组,然后生成 URL.例如:http://mysite.com/files/file.val1.val22.zip比我需要从这个链接下载文件...

I split string from cell data to Arrays and than generate URL. for example: http://mysite.com/files/file.val1.val22.zip Than i need to download file from this link...

我可以自动完成这个过程吗?

Can I do this process automaticaly ?

推荐答案

此示例函数将检索您的 zip 文件,并将其放入您的 Google Drive 文件夹StackOverflow"中.您还可以从 this gist 下载更完整的版本.

This example function will retrieve your zip file, and place it into your Google Drive in folder "StackOverflow". You can also download a more complete version from this gist.

function getFile(fileURL) {
  // see https://developers.google.com/apps-script/class_urlfetchapp
  var response = UrlFetchApp.fetch(fileURL);
  var fileBlob = response.getBlob()
  var folder = DocsList.getFolder('StackOverflow');
  var result = folder.createFile(fileBlob);
  debugger;  // Stop to observe if in debugger
}

例如:

getFile( "http://mysite.com/files/file.val1.val22.zip" );

请注意,您本身无法下载,因为您无法从 apps-script 访问 PC 的资源(例如文件系统).该文件仍在云"中……在这种情况下,它已从其所在的网站复制到 Google 云端硬盘中.不过,如果您正在运行云端硬盘应用,该文件现在将同步到您的 PC.

Note that you cannot download per se, since you have no access to your PC's resources (e.g. file system) from apps-script. The file is still in "the cloud"... in this case, it's been copied from the web site it was on, into Google Drive. If you're running the Drive app, though, the file will now sync to your PC.

这篇关于我可以从谷歌应用程序脚本生成的 URL 链接下载文件吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆