[英]Trouble downloading files in Google Apps Script web app after Chrome update
I've had a Google Apps Script web app running for a bit over a year which gave users an option to download a csv file.我有一个运行了一年多的 Google Apps 脚本 web 应用程序,它让用户可以选择下载 csv 文件。 It worked perfectly fine, although in the console it gave a warning about downloading from an iFrame being deprecated.
它工作得很好,尽管在控制台中它给出了关于从 iFrame 下载被弃用的警告。
After updating Chrome, I now get the following error when trying to download:更新 Chrome 后,我现在在尝试下载时收到以下错误:
Download is disallowed.
不允许下载。 The frame initiating or instantiating the download is sandboxed, but the flag 'allow-downloads' is not set.
启动或实例化下载的框架是沙盒的,但未设置标志“允许下载”。 See https://www.chromestatus.com/feature/5706745674465280 for more details.
有关详细信息,请参阅https://www.chromestatus.com/feature/5706745674465280 。
When following the above link, it provides the following information:当点击上述链接时,它提供以下信息:
Chrome is planning on removing this capability - ie Chrome is going to block all downloads initiated from or instantiated in a sandboxed iframe by default.
Chrome 正计划删除此功能——即默认情况下,Chrome 将阻止从沙盒 iframe 启动或实例化的所有下载。 The embedder may add "allow-downloads" to the sandbox attributes list to opt in. This allows content providers to restrict malicious or abusive downloads.
嵌入器可以将“允许下载”添加到沙盒属性列表以选择加入。这允许内容提供商限制恶意或滥用下载。
How can I add "allow-downloads" to the sandbox attributes in the Google Apps Script environment?如何将“允许下载”添加到 Google Apps 脚本环境中的沙箱属性? Alternatively, is there a workaround to enable downloading files?
或者,是否有启用下载文件的解决方法?
It is discussed here https://issuetracker.google.com/issues/157368720 that HtmlService.XFrameOptionsMode.ALLOWALL
should set allow-downloads
on GAS web app sandbox.这里讨论了https://issuetracker.google.com/issues/157368720
HtmlService.XFrameOptionsMode.ALLOWALL
应该在 GAS web 应用沙箱上设置allow-downloads
。 We should watch this issue for changes.我们应该关注这个问题的变化。
Include sandbox="allow-downloads"
in your iframe
tag, which contains the code that is used for downloading the CSV file.在
iframe
标记中包含sandbox="allow-downloads"
,其中包含用于下载 CSV 文件的代码。
Update as of 07/29/2020:截至 2020 年 7 月 29 日的更新:
The attribute "allow-downloads" has now been added to the sandbox attributes and there is no longer any issue downloading files.属性“allow-downloads”现在已添加到沙盒属性中,下载文件不再有任何问题。
There is one work around that I found if you have a download button, you can right click and open in a new tab.如果您有下载按钮,我发现有一种解决方法,您可以右键单击并在新选项卡中打开。 You have to rename the file but at least you can get it, until there is a fix.
你必须重命名文件,但至少你可以得到它,直到有一个修复。
Other than asking the users to right-click to download something, is there a workaround that allows websites to implement buttons that trigger a download on click?除了要求用户右键单击以下载某些内容之外,是否有一种解决方法可以让网站实现触发点击下载的按钮?
I must be missing something reading the feature that was implemented, but it seems there's no provisions for a website that makes NO USE of iframes and just uses anchor tags to trigger downloads.我一定错过了阅读已实施功能的内容,但似乎没有规定网站不使用 iframe,只使用锚标签来触发下载。
What is the recommended way to trigger a download now?现在触发下载的推荐方式是什么? I'm sure I am not understanding something here, as surely nobody in their right mind would ever even dream of pushing/accepting a change in production that forbids the very common use-case of implementing a button to download things.
我敢肯定我在这里没有理解某些东西,因为在他们正常的头脑中肯定没有人会梦想推动/接受禁止实现按钮来下载东西的非常常见的用例的生产更改。
So, I'm definitely missing something and being very thick here.所以,我肯定错过了一些东西,而且在这里很厚。 With the new version of Chromium, how can I make something like this work?
使用新版本的 Chromium,我怎样才能做出这样的事情?
<a download="my-download.pdf" target="_blank" href="my-download.pdf">Click here to download</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.