-
Notifications
You must be signed in to change notification settings - Fork 204
/
gcs-tokio.rs
53 lines (45 loc) · 1.45 KB
/
gcs-tokio.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// cargo run --example google-cloud
#[cfg(feature = "tokio")]
use awscreds::Credentials;
#[cfg(feature = "tokio")]
use awsregion::Region;
#[cfg(feature = "tokio")]
use s3::error::S3Error;
#[cfg(feature = "tokio")]
use s3::Bucket;
#[cfg(not(feature = "tokio"))]
fn main() {}
#[cfg(feature = "tokio")]
#[tokio::main]
async fn main() -> Result<(), S3Error> {
let bucket = Bucket::new(
"test-rust-s3",
Region::Custom {
region: "us-east1".to_owned(),
endpoint: "https://storage.googleapis.com".to_owned(),
},
Credentials::default()?,
)?
.with_path_style();
let s3_path = "test.file";
let test = b"I'm going to S3!";
let response_data = bucket.put_object(s3_path, test).await?;
assert_eq!(response_data.status_code(), 200);
let response_data = bucket.get_object(s3_path).await?;
assert_eq!(response_data.status_code(), 200);
assert_eq!(test, response_data.as_slice());
let response_data = bucket
.get_object_range(s3_path, 100, Some(1000))
.await
.unwrap();
assert_eq!(response_data.status_code(), 206);
let (head_object_result, code) = bucket.head_object(s3_path).await?;
assert_eq!(code, 200);
assert_eq!(
head_object_result.content_type.unwrap_or_default(),
"application/octet-stream".to_owned()
);
let response_data = bucket.delete_object(s3_path).await?;
assert_eq!(response_data.status_code(), 204);
Ok(())
}