mirror of
https://github.com/minio/minio-rs.git
synced 2025-12-06 23:36:52 +08:00
fix deprecated lifetime; update example file-uploader (#71)
* fix: deprecated elided_lifetimes_in_associated_constant * fix warnings * update: example file-file-uploader
This commit is contained in:
parent
8fb211ae0e
commit
75ea23aaf1
@ -26,7 +26,7 @@ http = "0.2.9"
|
|||||||
hyper = { version = "0.14.27", features = ["full"] }
|
hyper = { version = "0.14.27", features = ["full"] }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
md5 = "0.7.0"
|
md5 = "0.7.0"
|
||||||
multimap = "0.9.0"
|
multimap = "0.10.0"
|
||||||
os_info = "3.7.0"
|
os_info = "3.7.0"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
regex = "1.9.4"
|
regex = "1.9.4"
|
||||||
@ -38,6 +38,9 @@ tokio-stream = "0.1.14"
|
|||||||
tokio-util = { version = "0.7.8", features = ["io"] }
|
tokio-util = { version = "0.7.8", features = ["io"] }
|
||||||
urlencoding = "2.1.3"
|
urlencoding = "2.1.3"
|
||||||
xmltree = "0.10.3"
|
xmltree = "0.10.3"
|
||||||
|
log = "0.4.20"
|
||||||
|
env_logger = "0.11.2"
|
||||||
|
home = "0.5.9"
|
||||||
|
|
||||||
[dependencies.reqwest]
|
[dependencies.reqwest]
|
||||||
version = "0.11.20"
|
version = "0.11.20"
|
||||||
|
|||||||
@ -1,11 +1,18 @@
|
|||||||
|
use log::{error, info};
|
||||||
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs, UploadObjectArgs};
|
use minio::s3::args::{BucketExistsArgs, MakeBucketArgs, UploadObjectArgs};
|
||||||
use minio::s3::client::Client;
|
use minio::s3::client::Client;
|
||||||
use minio::s3::creds::StaticProvider;
|
use minio::s3::creds::StaticProvider;
|
||||||
use minio::s3::http::BaseUrl;
|
use minio::s3::http::BaseUrl;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let base_url = "https://play.min.io".parse::<BaseUrl>()?;
|
env_logger::init(); // Note: set environment variable RUST_LOG="INFO" to log info and higher
|
||||||
|
|
||||||
|
//let base_url = "https://play.min.io".parse::<BaseUrl>()?;
|
||||||
|
let base_url: BaseUrl = "http://192.168.178.227:9000".parse::<BaseUrl>()?;
|
||||||
|
|
||||||
|
info!("Trying to connect to MinIO at: `{:?}`", base_url);
|
||||||
|
|
||||||
let static_provider = StaticProvider::new(
|
let static_provider = StaticProvider::new(
|
||||||
"Q3AM3UQ867SPQQA43P2F",
|
"Q3AM3UQ867SPQQA43P2F",
|
||||||
@ -21,15 +28,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let bucket_name = "asiatrip";
|
let bucket_name: &str = "asiatrip";
|
||||||
|
|
||||||
// Check 'asiatrip' bucket exist or not.
|
// Check 'bucket_name' bucket exist or not.
|
||||||
let exists = client
|
let exists: bool = client
|
||||||
.bucket_exists(&BucketExistsArgs::new(&bucket_name).unwrap())
|
.bucket_exists(&BucketExistsArgs::new(&bucket_name).unwrap())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Make 'asiatrip' bucket if not exist.
|
// Make 'bucket_name' bucket if not exist.
|
||||||
if !exists {
|
if !exists {
|
||||||
client
|
client
|
||||||
.make_bucket(&MakeBucketArgs::new(&bucket_name).unwrap())
|
.make_bucket(&MakeBucketArgs::new(&bucket_name).unwrap())
|
||||||
@ -37,20 +44,33 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload '/home/user/Photos/asiaphotos.zip' as object name
|
// File we are going to upload to the bucket
|
||||||
// 'asiaphotos-2015.zip' to bucket 'asiatrip'.
|
let filename: &Path = Path::new("/home/user/Photos/asiaphotos.zip");
|
||||||
|
|
||||||
|
// Name of the object that will be stored in the bucket
|
||||||
|
let object_name: &str = "asiaphotos-2015.zip";
|
||||||
|
|
||||||
|
info!("filename {}", &filename.to_str().unwrap());
|
||||||
|
|
||||||
|
// Check if the file exists
|
||||||
|
let file_exists: bool = filename.exists();
|
||||||
|
if !file_exists {
|
||||||
|
error!("File `{}` does not exist!", filename.display());
|
||||||
|
()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upload 'filename' as 'object_name' to bucket 'bucket_name'.
|
||||||
client
|
client
|
||||||
.upload_object(
|
.upload_object(
|
||||||
&mut UploadObjectArgs::new(
|
&mut UploadObjectArgs::new(&bucket_name, &object_name, &filename.to_str().unwrap())
|
||||||
&bucket_name,
|
|
||||||
"asiaphotos-2015.zip",
|
|
||||||
"/home/user/Photos/asiaphotos.zip",
|
|
||||||
)
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("'/home/user/Photos/asiaphotos.zip' is successfully uploaded as object 'asiaphotos-2015.zip' to bucket 'asiatrip'.");
|
info!(
|
||||||
|
"file `{}` is successfully uploaded as object `{object_name}` to bucket `{bucket_name}`.",
|
||||||
|
filename.display()
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,4 +13,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#![allow(clippy::tabs_in_doc_comments)]
|
||||||
|
#![allow(clippy::result_large_err)]
|
||||||
|
#![allow(clippy::too_many_arguments)]
|
||||||
pub mod s3;
|
pub mod s3;
|
||||||
|
|||||||
@ -2333,9 +2333,9 @@ pub struct PostPolicy<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PostPolicy<'a> {
|
impl<'a> PostPolicy<'a> {
|
||||||
const EQ: &str = "eq";
|
const EQ: &'static str = "eq";
|
||||||
const STARTS_WITH: &str = "starts-with";
|
const STARTS_WITH: &'static str = "starts-with";
|
||||||
const ALGORITHM: &str = "AWS4-HMAC-SHA256";
|
const ALGORITHM: &'static str = "AWS4-HMAC-SHA256";
|
||||||
|
|
||||||
/// Returns post policy with given bucket name and expiration
|
/// Returns post policy with given bucket name and expiration
|
||||||
///
|
///
|
||||||
|
|||||||
@ -35,12 +35,10 @@ use async_recursion::async_recursion;
|
|||||||
use bytes::{Buf, Bytes};
|
use bytes::{Buf, Bytes};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use hyper::http::Method;
|
use hyper::http::Method;
|
||||||
use os_info;
|
|
||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::Read;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use xmltree::Element;
|
use xmltree::Element;
|
||||||
@ -48,9 +46,6 @@ use xmltree::Element;
|
|||||||
mod list_objects;
|
mod list_objects;
|
||||||
mod listen_bucket_notification;
|
mod listen_bucket_notification;
|
||||||
|
|
||||||
pub use list_objects::*;
|
|
||||||
pub use listen_bucket_notification::*;
|
|
||||||
|
|
||||||
/// Client Builder manufactures a Client using given parameters.
|
/// Client Builder manufactures a Client using given parameters.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ClientBuilder {
|
pub struct ClientBuilder {
|
||||||
@ -706,7 +701,7 @@ impl Client {
|
|||||||
|
|
||||||
async fn calculate_part_count<'a>(
|
async fn calculate_part_count<'a>(
|
||||||
&self,
|
&self,
|
||||||
sources: &'a mut Vec<ComposeSource<'_>>,
|
sources: &'a mut [ComposeSource<'_>],
|
||||||
) -> Result<u16, Error> {
|
) -> Result<u16, Error> {
|
||||||
let mut object_size = 0_usize;
|
let mut object_size = 0_usize;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|||||||
@ -117,7 +117,7 @@ impl Client {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let records_res: Result<NotificationRecords, Error> =
|
let records_res: Result<NotificationRecords, Error> =
|
||||||
serde_json::from_str(&s).map_err(|e| e.into());
|
serde_json::from_str(s).map_err(|e| e.into());
|
||||||
return Some((records_res, reader));
|
return Some((records_res, reader));
|
||||||
}
|
}
|
||||||
Err(e) => return Some((Err(e.into()), reader)),
|
Err(e) => return Some((Err(e.into()), reader)),
|
||||||
|
|||||||
@ -418,7 +418,6 @@ impl BaseUrl {
|
|||||||
port: self.port,
|
port: self.port,
|
||||||
path: String::from("/"),
|
path: String::from("/"),
|
||||||
query: query.clone(),
|
query: query.clone(),
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if bucket_name.is_none() {
|
if bucket_name.is_none() {
|
||||||
|
|||||||
@ -1198,7 +1198,7 @@ pub struct PrefixFilterRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixFilterRule {
|
impl PrefixFilterRule {
|
||||||
pub const NAME: &str = "prefix";
|
pub const NAME: &'static str = "prefix";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -1208,7 +1208,7 @@ pub struct SuffixFilterRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SuffixFilterRule {
|
impl SuffixFilterRule {
|
||||||
pub const NAME: &str = "suffix";
|
pub const NAME: &'static str = "suffix";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#Note start this script from minio-rs, not from directory tests
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|||||||
@ -86,7 +86,7 @@ struct ClientTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ClientTest {
|
impl ClientTest {
|
||||||
const SQS_ARN: &str = "arn:minio:sqs::miniojavatest:webhook";
|
const SQS_ARN: &'static str = "arn:minio:sqs::miniojavatest:webhook";
|
||||||
|
|
||||||
fn new(
|
fn new(
|
||||||
base_url: BaseUrl,
|
base_url: BaseUrl,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user