Crates.io | trackable_s3_stream |
lib.rs | trackable_s3_stream |
version | 0.2.0 |
source | src |
created_at | 2024-02-10 18:15:06.088514 |
updated_at | 2024-02-10 23:16:18.678647 |
description | AWS S3 stream implementation with callback to track progress |
homepage | |
repository | https://github.com/sapessi/trackable_s3_stream |
max_upload_size | |
id | 1135105 |
size | 106,227 |
This library exposes an implementation of hyper::Stream
that can be used as body for S3 requests with the AWS SDK for Rust. The stream object can send a callback with the current status of the stream.
let mut body = TrackableBodyStream::try_from(PathBuf::from("./examples/sample.jpeg")).map_err(|e| {
panic!("Could not open sample file: {}", e);
}).unwrap();
let bar = ProgressBar::new(body.content_length() as u64);
body.set_callback(move |tot_size: u64, sent: u64, cur_buf: u64| {
bar.inc(cur_buf as u64);
if sent == tot_size {
bar.finish();
}
});
let sdk_config = aws_config::from_env().load().await;
let s3_client = Client::new(&sdk_config);
let bucket = &args[1];
match s3_client.put_object()
.bucket(bucket)
.key("tracked_sample.jpeg")
.content_length(body.content_length())
.body(body.to_s3_stream())
.send().await {
Ok(_) => {
println!("Upload complete");
},
Err(e) => {
panic!("Failed to upload object: {}", e);
}
}
Test the indicaif
example by passing a bucket name
cargo run --example indicatif your_bucket_name