Skip to content

Latest commit

 

History

History
117 lines (92 loc) · 2.94 KB

README.md

File metadata and controls

117 lines (92 loc) · 2.94 KB

Google Cloud Storage Kotlin Sample

Open in Cloud Shell

Description

This sample application demonstrates how to invoke the Google Cloud Storage API from Kotlin.

The app is a command-line tool that implements the following Google Cloud Storage operations:

  1. Create a bucket
  2. List buckets
  3. List blobs in a bucket
  4. Upload a file to a bucket
  5. Download a blob from a bucket
  6. Delete a blob
  7. Delete a bucket

Examples:

java -jar build/libs/storage.jar create my_awesome_bucket
java -jar build/libs/storage.jar upload resources/upload/dog.jpg my_awesome_bucket

Quickstart

Setup

Build

  • Clone the repository
    git clone https://github.com/GoogleCloudPlatform/kotlin-samples
    cd kotlin-samples/storage
  • Build the project with Gradle Wrapper:
    # run with "-info" flag to print potential errors
    ./gradlew build -info

You should now have a 'storage.jar' file under build/libs/

Running the sample

You can run Google Cloud Storage actions by supplying any of the below commands to the storage.jar file:

usage

Prints syntax of commands implemented in the sample

java -jar build/libs/storage.jar usage

create

Creates a new bucket

java -jar build/libs/storage.jar create <bucket>

info

Gives details about a bucket or a blob

  • To list all buckets in your storage
    java -jar build/libs/storage.jar info
  • To list all blobs in a bucket
    java -jar build/libs/storage.jar info <bucket>

upload

Uploads a file to a bucket

  • Letting the program infer blob name from localFilePath
    java -jar build/libs/storage.jar upload <localFilePath> <bucket>
  • Providing blob name
    java -jar build/libs/storage.jar upload <localFilePath> <bucket> <blob>

download

Downloads a blob from a bucket to your computer

java -jar build/libs/storage.jar download <bucket> <blob> <localFilePath>

delete

Deletes a bucket or a blob

  • To delete a bucket
    java -jar build/libs/storage.jar delete <bucket>
  • To delete a blob
    java -jar build/libs/storage.jar delete <bucket> <blob>

Head to storageTest.kt to see actual tests.

Contributing changes

Licensing