rust-s3 - Documentation
Tiny Rust library for working with Amazon S3
Increasingly more loosly based on crates.io implementation.
Very modest interface towards Amazon S3.
Supports put
, get
and list
, with delete
on the roadmap and will be done eventually,
probably around the time I discover I need it in some other project :).
The main (and probably only) cool feature is that put
commands return a presigned link to the file you uploaded.
This means you can upload to s3, and give the link to select people without having to worry about publicly accessible files on S3.
Getter and setter functions exist for all Link
params... You don't really have to touch anything there, maybe amz-expire
,
it is configured for one week which is the maximum Amazon allows ATM.
In your Cargo.toml
[dependencies]
rust-s3 = '0.2.3'
extern crate s3;
use s3::{Bucket, put_s3, get_s3, list_s3};
const AWS_ACCESS: &'static str = "access_key";
const AWS_SECRET: &'static str = "secret_key";
fn main () {
// Bucket instance
let bucket = Bucket::new(S3_BUCKET.to_string(),
None,
AWS_ACCESS.to_string(),
AWS_SECRET.to_string(),
None);
// Put
let put_me = "I want to go to S3".to_string();
let url = put_s3(&bucket,
&"/",
&put_me.as_bytes());
println!("{}", url);
// List
let bytes = list_s3(&bucket,
&"/",
&"/",
&"/");
let string = String::from_utf8_lossy(&bytes);
println!("{}", string);
// Get
let path = &"test_file";
let mut buffer = match File::create(path) {
Ok(x) => x,
Err(e) => panic!("{:?}, {}", e, path)
};
let bytes = get_s3(&bucket, Some(&path));
match buffer.write(&bytes) {
Ok(_) => {} // info!("Written {} bytes from {}", x, path),
Err(e) => panic!("{:?}", e)
}
}