简体   繁体   English

我可以设置我的 Node.js 后端访问我的 Google Drive 以列出/下载/上传吗?

[英]Can I set my Node.js Backend to access my Google Drive to list/download/upload?

I want my back-end to use the Google Drive API to be able to list/upload/download files from a normal google drive folder (as opposed to a cloud bucket).我希望我的后端使用 Google Drive API 能够从普通的 Google Drive 文件夹(而不是云存储桶)列出/上传/下载文件。 But not the user's Google Drive, only MY drive.但不是用户的 Google Drive,只有 MY drive。

As far as the end-user is concerned they would just be on my site but when they upload a file, my back-end would receive it and store it on MY google drive.就最终用户而言,他们只会在我的网站上,但是当他们上传文件时,我的后端会收到它并将其存储在我的谷歌驱动器上。 Same for a simple list of files in the folder, I just want them to click my front-end button and have it send a call to my back end, then my back-end sends a call to the google API and returns a list.... effectively making my back-end the middle man for my google Drive.对于文件夹中的简单文件列表也是如此,我只希望他们单击我的前端按钮并让它向我的后端发送调用,然后我的后端向谷歌 API 发送调用并返回一个列表。 ...有效地使我的后端成为我的谷歌驱动器的中间人。 So that my users don't need a google account to access my site这样我的用户就不需要谷歌帐户来访问我的网站

My reasoning is I want my users to NOT need a google account, but I will still need to share these folders with contractors.我的理由是我希望我的用户不需要谷歌帐户,我仍然需要与承包商共享这些文件夹。 The contractors can have a google account, that doesn't bother me, And I don't want to have to re-invent the wheel by building a separate front-end for my contractors to download these folders when Google Drive already has perfectly working UI that will zip a folder and download it already built.承包商可以有一个谷歌帐户,这不会打扰我,而且我不想通过为我的承包商构建一个单独的前端来重新发明轮子,以便在 Google Drive 已经完美运行时下载这些文件夹UI 将 zip 一个文件夹并下载它已经构建。

So I want: User -> front-end -> my backend -> google drive所以我想要:用户->前端->我的后端->谷歌驱动器

I have seen posts on doing this for other services, like analytics and calendar, but I really need drive capabilities.我已经看到有关为其他服务(例如分析和日历)执行此操作的帖子,但我确实需要驱动功能。

A user could be either my client who needs to upload and download OR my client's clients (who will only ever need to upload)用户可以是我需要上传和下载的客户,也可以是我客户的客户(他们只需要上传)

Main Question: Can I set my NodeJS Back-end to access my Google Drive to list/download/upload主要问题:我可以将我的 NodeJS 后端设置为访问我的 Google Drive 以列出/下载/上传吗

If it is possible:如果有可能:

How, and should I?怎么做,我应该怎么做? As I write this, I am thinking of issues... like, will uploading a file from Front-end to back-end then to google drive be too cumbersome to be practical?当我写这篇文章时,我正在考虑一些问题......比如,将文件从前端上传到后端然后到谷歌驱动器是否太麻烦而不实用? (These are video files that could be around 300-400mb). (这些是大约 300-400mb 的视频文件)。

If not possible OR it is too cumbersome:如果不可能或者太麻烦:

Can anyone suggest anything that will make access to Google Cloud bucket folders easier?任何人都可以提出任何可以更轻松地访问 Google Cloud 存储桶文件夹的建议吗? Package? Package? Example?例子? Method?方法? Tutorial?教程?


Frontend: VueJS with axios前端:带有 axios 的 VueJS

Backend: super basic node/express API/back-end on an AWS ec2 server后端:AWS ec2 服务器上的超级基本节点/express API/后端

The short Answer is Yes.简短的回答是肯定的。

The way to do this is with a service account as these accounts are special credentials to be used by a service.这样做的方法是使用服务帐户,因为这些帐户是服务使用的特殊凭据。 These accounts are of the form: service-account-name@project-id.iam.gserviceaccount.com .这些帐户的格式为: service-account-name@project-id.iam.gserviceaccount.com

Once you have the service account you will need to grant access to this service account on the Google Drive location.拥有服务帐户后,您需要在 Google Drive 位置授予对该服务帐户的访问权限。 To grant access to this service account share the location (files or folders) with this account, as if you were sharing the files with another user, just by adding the email on the edit permitions.要授予对此服务帐户的访问权限,请与此帐户共享位置(文件或文件夹),就像您与其他用户共享文件一样,只需在编辑许可上添加 email。

And Finally to manipulate the files there programatically you can use the NodeJS Client Library which will make the task easier than manipulate the API calls directly.最后,要以编程方式操作那里的文件,您可以使用NodeJS 客户端库,这将使任务比直接操作 API 调用更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js - 无法从 Google Drive API 访问我的帐户 - Node.js - Can't access my account from the Google Drive API 仅从我的应用程序访问我的后端node.js - access my backend node.js only from my app 前端的谷歌选择器(用户登录 reactJS)和后端的谷歌驱动器下载(node.js),API v3 - Google picker on frontend (user login in reactJS) and google drive download on backend (node.js), API v3 Google Drive API混乱,如何下载文件夹内容? (的node.js) - Confusion on Google Drive API, how can I download contents of folders? (node.js) 我可以使用 Netlify 为我的 node.js 后端托管我的 React Web 应用和 Heroku 吗? - Can I use Netlify to host my React web app and Heroku for my node.js backend? 如何保护我的 Node.js 后端 api 数据? - How can I secure my Node.js backend api data? 我无法从外部访问我的AWS EC2上的node.js服务器 - I can't access my node.js server on my AWS EC2 isntance from the outside Node.js-通过请求从Google云端硬盘下载文件 - Node.js - Download File from Google Drive via request Node.js Google Drive api 下载文件错误 - Node.js Google Drive api Download file error 在 Node.JS 中从谷歌驱动器下载公共图像 - Download public images from google drive in Node.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM