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:
- Create a bucket
- List buckets
- List blobs in a bucket
- Upload a file to a bucket
- Download a blob from a bucket
- Delete a blob
- Delete a bucket
Examples:
build/install/storage/bin/storage create my_awesome_bucket
build/install/storage/bin/storage upload resources/upload/dog.jpg my_awesome_bucket
- Enable Storage API.
- Set up authentication.
- 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 installDist -info
You should now have a 'storage.jar' file under build/libs/
You can run Google Cloud Storage actions by supplying any of the below commands to the storage.jar file:
Prints syntax of commands implemented in the sample
build/install/storage/bin/storage usage
Creates a new bucket
build/install/storage/bin/storage create <bucket>
Gives details about a bucket or a blob
- To list all buckets in your storage
build/install/storage/bin/storage info
- To list all blobs in a bucket
build/install/storage/bin/storage info <bucket>
Uploads a file to a bucket
- Letting the program infer blob name from localFilePath
build/install/storage/bin/storage upload <localFilePath> <bucket>
- Providing blob name
build/install/storage/bin/storage upload <localFilePath> <bucket> <blob>
Downloads a blob from a bucket to your computer
build/install/storage/bin/storage download <bucket> <blob> <localFilePath>
Deletes a bucket or a blob
- To delete a bucket
build/install/storage/bin/storage delete <bucket>
- To delete a blob
build/install/storage/bin/storage delete <bucket> <blob>
Head to storageTest.kt to see actual tests.
- See CONTRIBUTING.md
- See LICENSE