英文:
How to know when Google show confirm after download Google Drive with field 'webContentLink'
问题
I understand your request. Here's the translated part:
我正在使用 Google Drive API v3,我使用 files.get
方法来获取文件,并使用字段 webContentLink
(https://developers.google.com/drive/api/reference/rest/v3/files/get)来下载文件。
我的下载按钮链接如下:
<a href={file.webContentLink} download={file.name}>下载文件</a>
我的问题是:当点击下载按钮时,有时会显示确认信息 'Google Drive 无法扫描此文件以防病毒',并替换我的网站网址。我想要检测点击后的 webContentLink
是否会显示确认信息。如果显示确认信息,我想要添加 target="_blank"
以在新标签页中打开下载。
我尝试查看链接参考中的字段(https://developers.google.com/drive/api/reference/rest/v3/files),以查找一个可以检测到这一情况的布尔字段,但我仍然不清楚。
谢谢您的帮助。
英文:
I'm working with Google Drive API v3, I use method files.get
to get a file and download file with field webContentLink
(https://developers.google.com/drive/api/reference/rest/v3/files/get)
My button link download look like this:
<a href={file.webContentLink} download={file.name}>Download file</a>
My problem: when click download button. Sometime It will show a comfirm 'Google Drive can't scan this file for viruses' and replace my website url. I want detect when webContentLink
after click will show a confirm. If it show confirm, I will add target="_blank"
to open download in new tab.
I try view field in link reference (https://developers.google.com/drive/api/reference/rest/v3/files) to find a boolean field detect that but I still don't know.
Thanks for your help.
答案1
得分: 1
根据我所知,使用Drive API无法检测何时会出现该消息。但是,当您尝试下载大于100 MB的文件时,会出现消息“无法扫描文件以查找病毒...超出了Google可以扫描的最大文件大小。此文件可能会损害您的计算机,因此只有在您了解风险后才能下载此文件。”没有官方文件明确说明下载文件大小的问题,但您可以在几个网站上找到相关信息。我也在我的端上进行了测试,对于大于100 MB的文件,我得到了相同的结果。
对于您的请求“我想检测在单击webContentLink后何时显示确认”,您可以检索文件的大小,这样您就知道如果文件小于100 MB,则会下载文件而不会出现警告消息。
还要考虑的另一件事是,尝试下载文件时可能会收到不同的消息,不一定涉及文件的大小。例如,还有另一种类型的消息,如下所示:
这种文件类型可能危险...“文件名”是一种可能会损害您的计算机的文件类型。只有在您了解风险后才能下载此文件。
这种其他消息通常在尝试下载可执行文件(如.exe
文件)时出现,因此您可能还需要检索文件的mimeType
,以便知道文件类型是否不同于.exe
,那么它就不会显示特定的警告消息。
**注意:**由于您正在使用files.get
方法,您还可以使用它来检索文件的size
和mimeType
。
参考资料:
英文:
As far as I know, there is no option with the Drive API to detect when you will get that message. However, the message Can't scan file for viruses ... exceeds the maximum file size that Google can scan. This file might harm your computer, so only download this file if you understand the risks.
Appears when you're trying to download a file larger than 100 MB. There is no official documentation where it says about the download file size, but you can find it on several websites. I also tested on my side and got the same result with files larger than 100 MB.
For your request "I want detect when webContentLink after click will show a confirm", you can retrieve the size of a file, that way you know if the file is less than 100 MB then it will download the file without that warning message.
Another thing to consider, you may get different messages when trying to download a file, not necessarily regarding the size of the file. For example, there is another type of message that says:
This file type might be dangerous ... "NameOfFile" is a file type that might harm your computer. Only download this file if you understand the risks.
That other message usually happens when trying to download an executable file, like .exe
files, so you may need to retrieve the mimeType
of the file too, that way you know if file type is different than .exe.
it will not show that specific warning.
Note: Since you're using the files.get
method, you can also use it to retrieve the size
and mimeType
of the file.
References:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论