简体   繁体   中英

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). But not the user's Google Drive, only 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. 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.

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

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).

If not possible OR it is too cumbersome:

Can anyone suggest anything that will make access to Google Cloud bucket folders easier? Package? Example? Method? Tutorial?


Frontend: VueJS with axios

Backend: super basic node/express API/back-end on an AWS ec2 server

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 .

Once you have the service account you will need to grant access to this service account on the Google Drive location. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM