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:
java -jar build/libs/storage.jar create my_awesome_bucket
java -jar build/libs/storage.jar 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 build -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
java -jar build/libs/storage.jar usage
Creates a new bucket
java -jar build/libs/storage.jar create <bucket>
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>
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>
Downloads a blob from a bucket to your computer
java -jar build/libs/storage.jar download <bucket> <blob> <localFilePath>
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.
- See CONTRIBUTING.md
- See LICENSE