mirror of
https://github.com/minio/minio-rs.git
synced 2025-12-06 15:26:51 +08:00
Add file-uploader example (#49)
Also add some basic fields to Cargo.toml to prepare for initial release.
This commit is contained in:
parent
4676ae8a57
commit
e5f6b16051
@ -2,6 +2,11 @@
|
||||
name = "minio"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["MinIO Dev Team <dev@min.io>"]
|
||||
description = "MinIO SDK for Amazon S3 compatible object storage access"
|
||||
license = "Apache-2.0"
|
||||
repository = "https://github.com/minio/minio-rs"
|
||||
readme = "README.md"
|
||||
|
||||
[dependencies]
|
||||
hyper = { version = "0.14.27", features = ["full"] }
|
||||
@ -35,3 +40,6 @@ os_info = "3.7.0"
|
||||
[dependencies.reqwest]
|
||||
version = "0.11.20"
|
||||
features = ["native-tls", "blocking", "rustls-tls", "stream"]
|
||||
|
||||
[[example]]
|
||||
name = "file-uploader"
|
||||
|
||||
14
README.md
14
README.md
@ -13,8 +13,7 @@ use minio::s3::http::BaseUrl;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut base_url = BaseUrl::from_string("play.min.io").unwrap();
|
||||
base_url.https = true;
|
||||
let base_url = BaseUrl::from_string("https://play.min.io".to_string()).unwrap();
|
||||
|
||||
let static_provider = StaticProvider::new(
|
||||
"Q3AM3UQ867SPQQA43P2F",
|
||||
@ -22,7 +21,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
None,
|
||||
);
|
||||
|
||||
let mut client = Client::new(base_url.clone(), Some(&static_provider), None, None).unwrap();
|
||||
let client = Client::new(
|
||||
base_url.clone(),
|
||||
Some(Box::new(static_provider)),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let bucket_name = "asiatrip";
|
||||
|
||||
@ -33,7 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
.unwrap();
|
||||
|
||||
// Make 'asiatrip' bucket if not exist.
|
||||
if !exist {
|
||||
if !exists {
|
||||
client
|
||||
.make_bucket(&MakeBucketArgs::new(&bucket_name).unwrap())
|
||||
.await
|
||||
@ -55,6 +60,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
.unwrap();
|
||||
|
||||
println!("'/home/user/Photos/asiaphotos.zip' is successfully uploaded as object 'asiaphotos-2015.zip' to bucket 'asiatrip'.");
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
56
examples/file-uploader.rs
Normal file
56
examples/file-uploader.rs
Normal file
@ -0,0 +1,56 @@
|
||||
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs, UploadObjectArgs};
|
||||
use minio::s3::client::Client;
|
||||
use minio::s3::creds::StaticProvider;
|
||||
use minio::s3::http::BaseUrl;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let base_url = BaseUrl::from_string("https://play.min.io".to_string()).unwrap();
|
||||
|
||||
let static_provider = StaticProvider::new(
|
||||
"Q3AM3UQ867SPQQA43P2F",
|
||||
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
|
||||
None,
|
||||
);
|
||||
|
||||
let client = Client::new(
|
||||
base_url.clone(),
|
||||
Some(Box::new(static_provider)),
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let bucket_name = "asiatrip";
|
||||
|
||||
// Check 'asiatrip' bucket exist or not.
|
||||
let exists = client
|
||||
.bucket_exists(&BucketExistsArgs::new(&bucket_name).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Make 'asiatrip' bucket if not exist.
|
||||
if !exists {
|
||||
client
|
||||
.make_bucket(&MakeBucketArgs::new(&bucket_name).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
// Upload '/home/user/Photos/asiaphotos.zip' as object name
|
||||
// 'asiaphotos-2015.zip' to bucket 'asiatrip'.
|
||||
client
|
||||
.upload_object(
|
||||
&mut UploadObjectArgs::new(
|
||||
&bucket_name,
|
||||
"asiaphotos-2015.zip",
|
||||
"/home/user/Photos/asiaphotos.zip",
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("'/home/user/Photos/asiaphotos.zip' is successfully uploaded as object 'asiaphotos-2015.zip' to bucket 'asiatrip'.");
|
||||
Ok(())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user