DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Upload Files to Google Cloud Storage with Python

Upload Files to Google Cloud Storage with Python

This tutorial will lead you to your first file upload to the Google Cloud Platform (GCP).

Mudit Chhabra user avatar by
Mudit Chhabra
CORE ·
Aug. 18, 20 · Tutorial
Like (4)
Save
Tweet
Share
26.88K Views

Join the DZone community and get the full member experience.

Join For Free

Google Cloud is a suite of cloud-based services just like AWS from Amazon and Azure from Microsoft. AWS dominates the market with Azure but Google's not far behind. Google Cloud Platform or GCP is the third largest cloud computing platform in the world, with a share of 9% closely followed by Alibaba Cloud. 

Amazon undoubtedly leads the market with a share of 33% but GCP is showing tremendous spike with the growth rate of whooping 83% in 2019. GCP leads AWS on the cost front, though. Google has a lesser number of services to offer but maintains its position as one of the most cost-effective cloud platform. 

Using GCP with Python

Python has been a go-to language for every modern age technology including Data Science, Machine Learning, Big Data, and Cloud. Just like other Cloud giants, GCP too supports Python.

This blog will focus on the storage service offered by Google called Google Cloud Storage or GCS. GCS can be used in python by installing google-cloud-storage API client library.

Google Cloud Storage allows you to store data on Google infrastructure with very high reliability, performance, and availability and can be used to distribute large data objects to users via direct download.

The Credentials

Accessing GCS through Python API requires credentials to be stored locally on your system in a JSON file format, which can be downloaded from the IAM and Admin service.

It requires the creation of a new service account.

New service account

The Code

Python
 




xxxxxxxxxx
1
14


 
1

          
2
from google.cloud import storage
3

          
4
# Setting credentials using the downloaded JSON file
5
client = storage.Client.from_service_account_json(json_credentials_path='credentials-python-storage.json')
6

          
7
# Creating bucket object
8
bucket = client.get_bucket('py-python')
9

          
10
# Name of the object to be stored in the bucket
11
object_name_in_gcs_bucket = bucket.blob('my_first_gcs_upload.png')
12

          
13
# Name of the object in local file system
14
object_name_in_gcs_bucket.upload_from_filename('gcs.png')



Bucket details
You would now be able to see your first file uploaded on the GCS bucket using a simple python code snippet.

I am glad you made this far in the blog. Hope you liked the tutorial.

If you need any assistance in making a new Google cloud account, do let me know in the comments section and I will be happy to help.

Cloud computing Google Cloud Storage Google (verb) Cloud storage Python (language) Upload

Opinions expressed by DZone contributors are their own.

Trending

  • Authorization: Get It Done Right, Get It Done Early
  • Transactional Outbox Patterns Step by Step With Spring and Kotlin
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Replacing Apache Hive, Elasticsearch, and PostgreSQL With Apache Doris

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: