[][src]Crate cloud_storage

This crate aims to simplify interacting with the Google Cloud Storage JSON API. Use it until Google releases a Cloud Storage Client Library for Rust. Shoutout to MyEmma for funding this free and open source project.

Google Cloud Storage is a product by Google that allows for cheap file storage, with a relatively sophisticated API. The idea is that storage happens in Buckets, which are filesystems with a globally unique name. You can make as many of these Buckets as you like!

This project talks to Google using a Service Account. A service account is an account that you must create in the cloud storage console. When the account is created, you can download the file service-account-********.json. Store this file somewhere on your machine, and place the path to this file in the environment parameter SERVICE_ACCOUNT. Environment parameters declared in the .env file are also registered. The service account can then be granted Roles in the cloud storage console. The roles required for this project to function are Service Account Token Creator and Storage Object Admin.


Add the following line to your Cargo.toml

cloud-storage = "0.3"

The two most important concepts are Buckets, which represent file systems, and Objects, which represent files.


Creating a new Bucket in Google Cloud Storage:

let bucket = Bucket::create(&NewBucket {
    name: "doctest-bucket".to_string(),

Connecting to an existing Bucket in Google Cloud Storage:

let bucket = Bucket::read("mybucket").unwrap();

Read a file from disk and store it on googles server:

let mut bytes: Vec<u8> = Vec::new();
for byte in File::open("myfile.txt").unwrap().bytes() {
Object::create("mybucket", &bytes, "myfile.txt", "text/plain");

Renaming/moving a file

let mut object = Object::read("mybucket", "myfile").unwrap();
object.name = "mybetterfile".to_string();

Removing a file

let object = Object::read("mybucket", "myfile").unwrap();



This complex object represents a Bucket that can be used to store and read files in Google Cloud Storage.


A Bucket Access Control object can be used to configure access on a bucket-wide level.


Default Object Access Control objects can be used the configure access that is used as a fallback in the abscence of more specific data.


An Hmac key is a secret key stored in Cloud Storage.


A file


Contains data about to access specific files.


A deserialized version of the service-account-********.json file. Used to authenticate requests.



The Buckets resource represents a bucket in Google Cloud Storage. There is a single global namespace shared by all buckets. For more information, see Bucket Name Requirements.


The structure of a error response returned by Google.


A model that can be used to insert new buckets into Google Cloud Storage.


A resource representing a file in Google Cloud Storage.


The struct is the parsed service account json file. It is publicly exported to enable easier debugging of which service account is currently used. It is of the type ServiceAccount.



Represents any of the ways storing something in Google Cloud Storage can fail.


Google provides a list of codes, but testing indicates that this list is not exhaustive.