#google #cloud #storage


A crate for uploading files to Google cloud storage, and for generating download urls

16 unstable releases (3 breaking)

0.6.1 Sep 13, 2020
0.6.0 Aug 18, 2020
0.5.2 Aug 7, 2020
0.4.2 Jun 22, 2020
0.3.3 Feb 9, 2020

#49 in Web programming

Download history 85/week @ 2020-06-01 104/week @ 2020-06-08 193/week @ 2020-06-15 237/week @ 2020-06-22 210/week @ 2020-06-29 158/week @ 2020-07-06 127/week @ 2020-07-13 127/week @ 2020-07-20 74/week @ 2020-07-27 134/week @ 2020-08-03 138/week @ 2020-08-10 75/week @ 2020-08-17 144/week @ 2020-08-24 127/week @ 2020-08-31 316/week @ 2020-09-07 1168/week @ 2020-09-14

677 downloads per month
Used in cloud-storage-sync

MIT license

3.5K SLoC

Cloud Storage

cloud-storage-rs on crates.io stripe-rust on docs.rs

A library that can be used to push blobs to Google Cloud Storage, and then generate download links to those files.


Add the following line to you Cargo.toml

cloud-storage = "0.6"


// create a new Bucket
let new_bucket = NewBucket { name: "mybucket", ..Default::default() }
let bucket = Bucket::create(new_bucket).await?;
// upload a file to our new bucket
let content = b"Your file is now on google cloud storage!";
bucket.upload(content, "folder/filename.txt", "application/text").await?;
let mut object = Object::create("mybucket", content, "folder/filename.txt", "application/text").await?;
// let's copy the file
object.copy("mybucket2: electric boogaloo", "otherfolder/filename.txt").await?;
// print a link to the file
println!("{}", object.download_url("new filename.txt", 1000)); // download link for 1000 seconds
// remove the file from the bucket

Authorization can be granted using the SERVICE_ACCOUNT environment variable, which should contain path to the service-account-*******.json file that contains the Google credentials. The service account requires the permission devstorage.full_control. This is not strictly necessary, so if you need this fixed, let me know!

The service account should also have the roles Service Account Token Creator (for generating access tokens) and Storage Object Admin (for generating sign urls to download the files).


If you're not (yet) interested in running an async executor, then cloud_storage exposes a sync api. To use it, enable the feature flag sync, and then call instead of calling function().await, call function_sync().


To run the tests for this project, first create an enviroment parameter (or entry in the .env file) named TEST_BUCKET. Make sure that this name is not already in use! The tests will create this bucket for its testing purposes. It will also create a couple of other buckets with this name as prefix, but these will be deleted again. Next, you will need a Google Cloud Storage project, for which you must create a service account. Download the service-account.json file and place the path to the file in the SERVICE_ACCOUNT environment parameter. Then, run

cargo test --tests -- --test-threads=1

The test-threads=1 is necessary so that the tests don't exceed the 2 per second bucket creating rate limit. (Depending on your internet speed, you may be able to use more than 1 test thread)


~464K SLoC