Struct s3::Bucket
[−]
[src]
pub struct Bucket { /* fields omitted */ }
Object holding info about an S3 bucket which provides easy access to S3 operations.
Example
use s3::{Bucket, Credentials}; let bucket_name = "rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials);
Methods
impl Bucket
[src]
fn new(name: &str, region: Region, credentials: Credentials) -> Bucket
Instantiate a new Bucket
.
Example
use s3::{Bucket, Credentials}; let bucket_name = "rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials);
fn get(&self, path: &str) -> S3Result<(Vec<u8>, u32)>
Gets file from an S3 path.
Example:
use s3::{Bucket, Credentials}; let bucket_name = "rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials); let (data, code) = bucket.get("/test.file").unwrap(); println!("Code: {}\nData: {:?}", code, data);
fn delete(&self, path: &str) -> S3Result<(Vec<u8>, u32)>
Delete file from an S3 path.
Example:
use s3::{Bucket, Credentials}; let bucket_name = &"rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials); let (_, code) = bucket.delete("/test.file").unwrap(); assert_eq!(204, code);
fn put(&self,
path: &str,
data: &[u8],
content_type: &str)
-> S3Result<(Vec<u8>, u32)>
path: &str,
data: &[u8],
content_type: &str)
-> S3Result<(Vec<u8>, u32)>
Put into an S3 bucket.
Example
use s3::{Bucket, Credentials}; let bucket_name = &"rust-s3-test"; let aws_access = &"access_key"; let aws_secret = &"secret_key"; let bucket_name = &"rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials); let content = "I want to go to S3".as_bytes(); let (_, code) = bucket.put("/test.file", content, "text/plain").unwrap(); assert_eq!(201, code);
fn list(&self,
prefix: &str,
delimiter: Option<&str>)
-> S3Result<(Vec<u8>, u32)>
prefix: &str,
delimiter: Option<&str>)
-> S3Result<(Vec<u8>, u32)>
List the contents of an S3 bucket.
Example
use std::str; use s3::{Bucket, Credentials}; let bucket_name = &"rust-s3-test"; let aws_access = &"access_key"; let aws_secret = &"secret_key"; let bucket_name = &"rust-s3-test"; let region = "us-east-1".parse().unwrap(); let credentials = Credentials::new("access_key", "secret_key", None); let bucket = Bucket::new(bucket_name, region, credentials); let (list, code) = bucket.list("/", Some("/")).unwrap(); assert_eq!(200, code); let string = str::from_utf8(&list).unwrap(); println!("{}", string);
fn name(&self) -> &str
Get a reference to the name of the S3 bucket.
fn host(&self) -> &str
Get a reference to the hostname of the S3 API endpoint.
fn region(&self) -> Region
Get the region this object will connect to.
fn access_key(&self) -> &str
Get a reference to the AWS access key.
fn secret_key(&self) -> &str
Get a reference to the AWS secret key.
fn token(&self) -> Option<&str>
Get a reference to the AWS token.
fn credentials(&self) -> &Credentials
Get a reference to the full Credentials
object used by this Bucket
.
fn set_credentials(&mut self, credentials: Credentials) -> Credentials
Change the credentials used by the Bucket, returning the existing credentials.
fn add_header(&mut self, key: &str, value: &str)
Add an extra header to send with requests to S3.
Add an extra header to send with requests. Note that the library already sets a number of headers - headers set with this method will be overridden by the library headers: * Host * Content-Type * Date * Content-Length * Authorization * X-Amz-Content-Sha256 * X-Amz-Date
fn extra_headers(&self) -> &Headers
Get a reference to the extra headers to be passed to the S3 API.
fn extra_headers_mut(&mut self) -> &mut Headers
Get a mutable reference to the extra headers to be passed to the S3 API.
fn add_query(&mut self, key: &str, value: &str)
Add an extra query pair to the URL used for S3 API access.
fn extra_query(&self) -> &Query
Get a reference to the extra query pairs to be passed to the S3 API.
fn extra_query_mut(&mut self) -> &mut Query
Get a mutable reference to the extra query pairs to be passed to the S3 API.
Trait Implementations
impl Clone for Bucket
[src]
fn clone(&self) -> Bucket
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more