我可以从Google Apps脚本生成的URL链接下载文件吗 [英] Can I download file from URL link generated by google apps script

查看:78
本文介绍了我可以从Google Apps脚本生成的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个参数:

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 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.

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

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