Uploading and Downloading Data

UPLOADING AND DOWNLOADING DATA

  • In this section, we will cover the different methods and tools available for uploading and downloading data to and from Google Cloud Storage.
  • We are going to discuss the following methods for uploading and downloading data.
  1. The gsutil command-line tool
  2. the Google Cloud Storage API
  3. the Google Cloud Storage web interface.
  • Let’s discuss the gsutil command line tool.
  • gsutil is a Python application that lets you access Cloud Storage from the command line. 
  • You can use gsutil to do a wide range of bucket and object management tasks, including:
  • Creating and deleting buckets.
  • Uploading, downloading, and deleting objects.
  • Listing buckets and objects.
  • Moving, copying, and renaming objects.
  • Editing object and bucket Access Control Lists (ACLs).

gsutil performs all operations, including uploads and downloads, using HTTPS and transport-layer security (TLS).

  • Let’s get started with gsutil
  • I will switch to my Google Cloud Console and activate Cloud Shell.
  • What is Cloud Shell?
  • Cloud Shell is an interactive shell environment for Google Cloud that lets you learn and experiment with Google Cloud and manage your projects and resources from your web browser.
  • With Cloud Shell, the Google Cloud CLI (gcloud) and other utilities you need are pre-installed, fully authenticated, up-to-date, and always available when you need them.
  •  Cloud Shell is free for all users.
  • Activate cloud shell on screen recording
  • Use the gsutil cp command to copy the image from the filesystem to the bucket you created:
  • gsutil cp README-cloudshell.txt gs://my-awesome-bucket
  • You’ve just stored an object in your bucket!

DOWNLOADING

  • Use the gsutil cp command to download the image you stored in your bucket to somewhere on your environment
  • gsutil cp gs://my-awesome-bucket/README-cloudshell.txt downloaded_readme.txt
  • You’ve just downloaded something from your bucket!

Copy the object to a folder in the bucket

  • gsutil cp gs://my-awesome-bucket/kitten.png gs://my-awesome-bucket/just-a-folder/kitten3.png

List contents of a bucket or folder

  • Use the gsutil ls command to list the contents at the top level of your bucket:
  • Here you have the contents at the top level of your bucket!

List details for an object

  • Use the gsutil ls command with the -l flag to get some details about the image
  • gsutil ls -l gs://my-awesome-bucket/kitten.png
  • Now you have just obtained information about the image’s size and date of creation.

Delete an object

  • Use the gsutil rm command to delete one of your images
  • gsutil rm gs://my-awesome-bucket/kitten.png
  • This copy of the image is no longer stored on Cloud Storage
  • We can also use the gsutil tool to create and delete buckets
    • Creating a bucket
      • Use the gsutil mb command and a unique name to create a bucket
      • gsutil mb -l us-east1 gs://my-awesome-bucket/
  • Deleting a bucket
    • Use the gsutil rm command with the -r flag to delete the bucket and anything inside of it
    • gsutil rm -r gs://my-awesome-bucket
  • Let’s discuss the Google Cloud Storage API
  • There are client libraries for interacting with Cloud Storage. We would be using the Python Client Library to demonstrate uploads and downloads.
  • Switch to cloud shell editor and explain
  • Finally the Google Cloud Storage web interface.
  • The Google Cloud Storage web interface is a user-friendly way to upload and download data to and from Google Cloud Storage. It allows you to easily upload and download data, manage your data, and perform other operations on your data.
  • Switch to cloud shell editor and explain

Scroll to Top