Skip to content

Instantly share code, notes, and snippets.

@nosarthur
Last active April 24, 2019 21:51
Show Gist options
  • Save nosarthur/d4c37bfb3025dedeae12d0581148fd8b to your computer and use it in GitHub Desktop.
Save nosarthur/d4c37bfb3025dedeae12d0581148fd8b to your computer and use it in GitHub Desktop.
google storage api

To use api, one needs to enable the credential

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

gsutil

The speed differs a lot with parallel upload. Unfortunately this option is only available in gsutil but not the apis.

gsutil -o GSUtil:parallel_composite_upload_threshold=150M cp big_file.tar.gz gs://somewhere

python api

To obtain the source code

pip install -U google-cloud-storage
from google.cloud import storage
storage_client = storage.Client()
bucket_name ='graphdb-us-central1'
bucket = storage_client.get_bucket(bucket_name)
 
// upload
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
 
// download
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
 
// delete
blob = bucket.blob(blob_name)
blob.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment