node.js -- 提供谷歌驱动文件的直接链接 [英] node.js -- provide direct link for google drive file

查看:61
本文介绍了node.js -- 提供谷歌驱动文件的直接链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用本网站上的另一个答案,我找到了这个 curl 脚本:

using another answer on this site, I was able to find this curl script:

#!/bin/bash
fileid="0Bz-w5tutuZIYY3h5YlMzTjhnbGM"
filename="MyFile.tar.gz"
curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}

能够下载大型 Google Drive 文件(显示警告页面).

which is able to download large Google Drive files (which show a warning page).

此外,我可以使用 pip install gdown 命令:

Additionally, I was able to us the pip install gdown command:

gdown https://drive.google.com/uc?id=0Bz-w5tutuZIYY3h5YlMzTjhnbGM

pip install youtube-dl 库:

youtube-dl https://drive.google.com/uc?id=0Bz-w5tutuZIYY3h5YlMzTjhnbGM`

我什至可以在 NODE.js 中运行 gdown 脚本:

I'm even able to run the gdown script from within NODE.js:

const {spawn} = require("child_process");
 var g = spawn("gdown", ["https://drive.google.com/uc?id=0Bz-w5tutuZIYY3h5YlMzTjhnbGM"]);
 g.stdout.on('data', (d) => {
    console.log(d.toString()); 
 });

 g.stderr.on('data', (d) => {
    console.log(d.toString()); 
 });

 g.on('close', (d) => {
    console.log("closed with: " + d.toString()); 
 });

问题:

我希望能够使用 Google 云端硬盘为网站托管大文件,为此我需要能够生成直接下载链接.我在想像向 mynodewebsite/GOOGLE_DRIVE_LINK 发出 GET 请求,甚至向 node.js 服务器发出套接字请求,要求它获取链接,然后等待生成的链接响应.

I want to be able to use Google Drive to host large files for a website, and to do that I need to be able to produce a direct download link. I was thinking something like making a GET request to mynodewebsite/GOOGLE_DRIVE_LINK, or even making a socket request to the node.js server asking it to get the link, and then waiting for the generated link response.

然而,虽然我可以使用上述方法慢慢下载文件,但我如何简单地返回/一个文件的直接链接?我是否需要将 google drive 文件下载到 node.js 服务器上,等待它完成处理,然后将该文件的路径返回给客户端,然后再将其删除?这会破坏大文件的目的,因为我想使用 Google Drive 作为完整的托管...

HOWEVER, although I'm able to slowly download the file using the above methods, how can I simply return the / a direct link to the file? DO I need to download the google drive file onto the node.js server, wait for it to finish processing, and then return the path to that file back to the client, and then delete it afterwards? That would kind of defeat the purpose for large files, since I want to use Google Drive as the complete hosting...

那么我怎样才能简单地返回直接的 Google Drive 下载链接而不是下载整个内容?

SO how can I simply return the direct Google Drive download LINK as opposed to downloading the whole thing?

当我尝试打开新创建的项目时:

When I try to open the newly created project:

推荐答案

当您想检索用于下载 Google Drive 中共享大文件的直接链接时,您可以使用 API 密钥使用端点.端点如下.

When you want to retrieve a direct link for downloading a shared large file in Google Drive, you can use the endpoint using API key. The endpoint is as follows.

https://www.googleapis.com/drive/v3/files/### fileId ###?alt=media&key=### API key ###

您可以使用端点作为直接链接并下载文件.

You can use the endpoint as the direct link and download the file.

这篇关于node.js -- 提供谷歌驱动文件的直接链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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