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 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
Partner Zones Build AI Agents That Are Ready for Production
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
Build AI Agents That Are Ready for Production

"Platform Engineering & DevOps" Trend Report is now LIVE! Learn how internal platforms help developers ship faster with less friction

Join this live webinar to learn safer rollout techniques for schema changes, index testing, and database migrations.

Related

  • Integrating Google Cloud Platform Services With Kubernetes
  • Reproducible SadTalker Pipeline in Google Colab for Single-Image, Single-Audio Talking-Head Generation
  • Engineering Performance: Technical Analysis of telecom-mas-agent vs Google Cloud Pub/Sub in High-Throughput Telecom Automation
  • Expert Guide: How to Slash Cloud Cost in 2025

Trending

  • A System Cannot Protect What It Does Not Understand
  • I Was Tired of Flying Blind With AI Agents, So I Built AgentDog
  • Building Threat Intelligence Pipelines Using Python, APIs, and Elasticsearch
  • Open-Source LLM Tools Worth Your Time
  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
33.4K 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
  • Reproducible SadTalker Pipeline in Google Colab for Single-Image, Single-Audio Talking-Head Generation
  • Engineering Performance: Technical Analysis of telecom-mas-agent vs Google Cloud Pub/Sub in High-Throughput Telecom Automation
  • Expert Guide: How to Slash Cloud Cost in 2025

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook