Download file from drive using appscript

2019-09-15 01:39发布

I have a file in Google Drive with id=0B3fqdol6s0bWZHV3RWpoV1gyWkk

And I created appscript to download it over a link automatically. The code looks like this

function doGet(e) {
  return HtmlService.createHtmlOutput(downloader());
}

function downloader() {
  var out = "<body onload='dllink.click()'>";
  out +="<a id='dllink' href='https://drive.google.com/uc?export=download&id=0B3fqdol6s0bWZHV3RWpoV1gyWkk'>wait will download automatically<a/>";
  out +="</body>";
  return out;
};

Then, I developed it as webapps so my friend can download it easily using link https://script.google.com/macros/s/AKfycbzzToo8gwgdj30FBLrjA1izcfv4rddjW6VClaEGuNXAqZAkIH7S/exec

It's working perfect on PC browser, but sadly, It can't work on mobile phone browser which doesn't support handle onload event or javascript.

So, is there any solution to make an appscript download a file based on its id automatically?

1条回答
Deceive 欺骗
2楼-- · 2019-09-15 02:02

Try it by using an iFrame:

function doGet(e) {
  return HtmlService.createHtmlOutput(downloader());
}

function downloader() {
  var out = "<iframe width=\"1\" height=\"1\" frameborder=\"0\" src=\"https://drive.google.com/uc?export=download&id=0B3fqdol6s0bWZHV3RWpoV1gyWkk\"></iframe>";
  return out;
};

*Backslashes are for escaping

查看更多
登录 后发表回答