simple_aws_s3/
lib.rs

1//! # Simple AWS S3
2//! Provides the simple way to work with AWS S3. It use reqwest to execute the reqwest.
3//!
4//! This package is developing while waiting the fully supported from [aws-sdk](https://github.com/awslabs/aws-sdk-rust) from Amazon.
5//! ### Features:
6//!
7//! + Post Presigned (Upload from browser)
8//! + Get Presigned (Download from browser)
9//! + Bucket Operations:
10//! + Object Operations:
11//!     + Head Object (Retrieve Information of an Object)
12//!     + Delete Object
13//!
14//! ### Examples:
15//! use chrono::Duration;
16//! use reqwest::multipart::{Form, Part};
17//! use reqwest::StatusCode;
18//! use simple_aws_s3::{PostPresignedInfo, S3};
19//!
20//! // Before run this example, please replace s3 config below by your config.
21//! const ACCESS_KEY: &str = "AKIAIOSFODNN7EXAMPLE";
22//! const SECRET_KEY: &str = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
23//! const REGION: &str = "us-east-1";
24//! const ENDPOINT: &str = "s3.amazonaws.com";
25//! const BUCKET: &str = "examplebucket";
26//!
27//! #[tokio::main]
28//! async fn main() {
29//!     let s3 = S3::new(BUCKET, REGION, ENDPOINT, ACCESS_KEY, SECRET_KEY);
30//!
31//!     let key = String::from("text.txt");
32//!     let content = "Hello world";
33//!
34//!     // Upload by Post Presigned
35//!     let PostPresignedInfo { upload_url, params } = s3
36//!         .generate_presigned_post(
37//!             key.clone(),
38//!             "plain/text",
39//!             10485760,
40//!             Duration::seconds(3600),
41//!             None,
42//!         )
43//!         .unwrap();
44//!     let mut form = Form::new();
45//!     for (key, value) in params {
46//!         form = form.text(key, value);
47//!     }
48//!     let part = Part::text(content).mime_str("plain/text").unwrap();
49//!     form = form.part("file", part);
50//!     let res = reqwest::Client::new()
51//!         .post(&upload_url)
52//!         .multipart(form)
53//!         .send()
54//!         .await
55//!         .unwrap();
56//!     assert_eq!(res.status(), StatusCode::NO_CONTENT);
57//!
58//!     // Download by Query Param (Get Presigned)
59//!     let download_url = s3.generate_presigned_get(&key, 3600).unwrap();
60//!     let res = reqwest::Client::new()
61//!         .get(&download_url)
62//!         .send()
63//!         .await
64//!         .unwrap();
65//!     assert_eq!(res.status(), StatusCode::OK);
66//!     assert_eq!(res.text().await.unwrap(), content);
67//! }
68//! + [Upload/Download](https://github.com/cptrodgers/simple-aws-s3/tree/master/examples)
69//! ```
70
71#[macro_use]
72extern crate serde;
73
74pub mod error;
75pub mod s3;
76pub mod s3_constant;
77pub mod s3_post_policy;
78pub mod s3_signer;
79pub mod s3_string_to_sign;
80
81// Export as main level
82pub use s3::*;
83pub use s3_constant::*;
84pub use s3_post_policy::*;
85pub use s3_signer::*;
86pub use s3_string_to_sign::*;
87
88// Export dependencies
89pub mod prelude {
90    pub use hmac;
91    pub use reqwest;
92    pub use sha2;
93}