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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

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

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Integrating Google Cloud Platform Services With Kubernetes
  • Expert Guide: How to Slash Cloud Cost in 2025
  • Building Product to Learn AI, Part 2: Shake and Bake
  • Strengthening Cloud Environments Through Python and SQL Integration

Trending

  • Next Evolution in Integration: Architecting With Intent Using Model Context Protocol
  • Traditional Testing and RAGAS: A Hybrid Strategy for Evaluating AI Chatbots
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Navigating and Modernizing Legacy Codebases: A Developer's Guide to AI-Assisted Code Understanding
  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).

By 
Mudit Chhabra user avatar
Mudit Chhabra
·
Aug. 18, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
32.7K 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.

Related

  • Integrating Google Cloud Platform Services With Kubernetes
  • Expert Guide: How to Slash Cloud Cost in 2025
  • Building Product to Learn AI, Part 2: Shake and Bake
  • Strengthening Cloud Environments Through Python and SQL Integration

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!