#google-cloud #cloud-storage #cloud #google #api-bindings #storage

cloud-storage-rs

MOVED TO crates.io/crates/cloud-storage A crate for uploading files to Google cloud storage, and for generating download urls

13 releases

0.4.3 Jul 10, 2020
0.4.2 Jul 10, 2020
0.2.4 Dec 17, 2019
0.1.5 Oct 25, 2019

#2341 in Web programming

Download history 9/week @ 2024-06-18 6/week @ 2024-06-25 184/week @ 2024-07-02 10/week @ 2024-07-09 74/week @ 2024-07-16 87/week @ 2024-07-23 97/week @ 2024-07-30 76/week @ 2024-08-06 123/week @ 2024-08-13 53/week @ 2024-08-20 2/week @ 2024-08-27 31/week @ 2024-09-03 25/week @ 2024-09-10 22/week @ 2024-09-17 88/week @ 2024-09-24 65/week @ 2024-10-01

210 downloads per month

MIT license

180KB
2.5K SLoC

MOVED TO cloud-storage

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.

Usage

Add the following line to you Cargo.toml

[dependencies]
cloud-storage = "0.4"

Examples

// create a new Bucket
let new_bucket = NewBucket { name: "mybucket", ..Default::default() }
let bucket = Bucket::create(new_bucket)?;
// 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")?;
let mut object = Object::create("mybucket", content, "folder/filename.txt", "application/text")?;
// let's copy the file
object.copy("mybucket2: electric boogaloo", "otherfolder/filename.txt")?;
// 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
object.delete()?;

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).

Testing

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)

Dependencies

~14–29MB
~574K SLoC