Struct simple_aws_s3::s3::S3

source ·
pub struct S3 { /* private fields */ }
Expand description

Work with S3 via this struct

Example:

use simple_aws_s3::*;
use chrono::Duration;

const ACCESS_KEY: &str = "AKIAIOSFODNN7EXAMPLE";
const SECRET_KEY: &str = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
const REGION: &str = "us-east-1";
const ENDPOINT: &str = "s3.amazonaws.com";
const BUCKET: &str = "examplebucket";

let s3 = S3::new(
    BUCKET,
    REGION,
    ENDPOINT,
    ACCESS_KEY,
    SECRET_KEY,
);

let res = s3.generate_presigned_post("example.png".into(), "image/png", 10485760, Duration::seconds(3600), None).unwrap();
assert_eq!(res.upload_url, "https://us-east-1.s3.amazonaws.com/examplebucket");
assert!(res.params.contains_key("policy"));
assert!(res.params.contains_key(S3_CRED_KEY));
assert!(res.params.contains_key(S3_DATE_KEY));
assert!(res.params.contains_key(S3_SIGNATURE_KEY));
assert!(!res.params.contains_key("acl"));

// Generate Presigned Get: Link to download example.png, expire ons 1 hour
let download_url = s3.generate_presigned_get("example.png", 3600).unwrap();
println!("URL to download: {}", download_url);

// Get information of an object
let head_req = s3.head_object("example.png").await?;

// Delete an object
let delete_req = s3.delete_object("example.png").await?;

Implementations§

source§

impl S3

source

pub fn new( bucket: impl Into<String>, region: impl Into<String>, endpoint: impl Into<String>, access_key: impl Into<String>, secret_key: impl Into<String> ) -> Self

source

pub fn bucket_url(&self) -> String

source

pub async fn head_object(&self, key: &str) -> Result<Response, Error>

source

pub async fn delete_object(&self, key: &str) -> Result<Response, Error>

source

pub fn prepare_simple_object_method( &self, key: &str, method: Method ) -> Result<Request, InvalidKeyLength>

source

pub fn generate_presigned_post( &self, key: String, content_type: &str, content_length: i64, expire_on: Duration, acl: Option<&str> ) -> Result<PostPresignedInfo, InvalidKeyLength>

source

pub fn generate_presigned_get( &self, key: &str, expires_on: i32 ) -> Result<String, Error>

Trait Implementations§

source§

impl Clone for S3

source§

fn clone(&self) -> S3

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for S3

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for S3

§

impl Send for S3

§

impl Sync for S3

§

impl Unpin for S3

§

impl !UnwindSafe for S3

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more