To use api, one needs to enable the credential
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"
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
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()