Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add files from Google Cloud Storage to Drive

I'm developing a backend service in NodeJS. It processes images from Google Cloud Storage by requesting a temporary link and sending this link to a third party analysis service. I'd also want the images to be added to a shared Google Drive folder. Is there any possible way to do this easily (e.g. by using the Drive API and posting the link to the file, instead of downloading the file and subsequently uploading it). In other words: does the Drive API accept links to files, instead of uploading them? Or is there any other clever way of sharing Google Cloud to Drive easily (as it's both Google services).

Thanks

like image 768
Flock Dawson Avatar asked Nov 18 '16 16:11

Flock Dawson


People also ask

How do I move files from Google Drive to Google cloud?

Transferring data from Google Drive to Google Cloud Storage We mount Google Drive using the google colab tools which requires authenticating in a separate brower window. Then we authenticate and connect our Google Cloud Storage project, list all buckets, and start copying files from Google Drive to our bucket.


2 Answers

The best way to do this right now would be to use a Google Colab notebook:

  1. Create a Google Colab notebook and connect to your GCP bucket and mount Google Drive to it:
# authenticate
from google.colab import auth
auth.authenticate_user()

# set your gcp project
!gcloud config set project my-project

# mount your drive
from google.colab import drive
drive.mount('/content/drive')
  1. Run a gsutil command to copy your GCP storage data to the mounted drive
!gsutil -q -m cp -r gs://my-bucket-name /content/drive/My\ Drive/
like image 191
Jakub Žitný Avatar answered Jan 04 '23 16:01

Jakub Žitný


I have done some searching but, I don't see a way to add files from Google Cloud Storage to Google Drive other than doing downloading and uploading them. Also AFAIK, gsutil, which Google Cloud Storage APIs can interact with, also supports downloading and uploading of files when sharing to other storage.

And, as answered in Cloud Storage - Frequently Asked Questions, Google Drive and Google Cloud Storage are two different storage services wherein both allow programmatic access to their functionality, but the goals of the APIs are quite different.

However, you may want to try using Request Endpoints wherein you can access Google Cloud Storage through three request endpoints (URIs). Which one you use depends on the operation you are performing.

IMPORTANT NOTE: The Google Cloud Storage URIs described on this page are subject to change.

You can use the following URLs to access an object:

XML API

storage.googleapis.com/<bucket>/<object> <bucket>.storage.googleapis.com/<object>

JSON API

www.googleapis.com/download/storage/v1/b/<bucket>/o/<object-encoded-as-URL-path-segment>?alt=media

These URLs support secure sockets layer (SSL) encryption, which means you can use either HTTP or HTTPS. If you authenticate to the Google Cloud Storage API using OAuth 2.0, you should use HTTPS.

You may want to also check Sharing and Collaboration for more information.

like image 38
Teyam Avatar answered Jan 04 '23 17:01

Teyam