1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

update aws-sdk deps

This commit is contained in:
Rob Ede 2023-11-07 03:27:23 +00:00
parent 0de1c02762
commit 1027b6e1fb
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
4 changed files with 418 additions and 286 deletions

682
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -8,8 +8,8 @@ actix-multipart.workspace = true
actix-web.workspace = true
actix-web-lab.workspace = true
aws-config = "0.56"
aws-sdk-s3 = "0.34"
aws-config = "0.57"
aws-sdk-s3 = "0.35"
dotenvy.workspace = true
env_logger.workspace = true
@ -18,3 +18,4 @@ log.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["io-util", "fs"] }
tokio-util = "0.7"

View File

@ -1,9 +1,8 @@
use std::env;
use actix_web::{error, web::Bytes, Error};
use aws_config::SdkConfig as AwsConfig;
use aws_sdk_s3::{primitives::ByteStream, Client as S3Client};
use futures_util::{stream, Stream, StreamExt as _, TryStreamExt as _};
use futures_util::{stream, StreamExt as _};
use tokio::{fs, io::AsyncReadExt as _};
use crate::{TempFile, UploadedFile};
@ -32,10 +31,7 @@ impl Client {
)
}
pub async fn fetch_file(
&self,
key: &str,
) -> Option<(u64, impl Stream<Item = Result<Bytes, actix_web::Error>>)> {
pub async fn fetch_file(&self, key: &str) -> Option<(u64, ByteStream)> {
let object = self
.s3
.get_object()
@ -50,7 +46,7 @@ impl Client {
.content_length()
.try_into()
.expect("file has invalid size"),
object.body.map_err(error::ErrorInternalServerError),
object.body,
))
}
@ -58,7 +54,7 @@ impl Client {
&self,
temp_files: Vec<TempFile>,
key_prefix: &str,
) -> Result<Vec<UploadedFile>, Error> {
) -> actix_web::Result<Vec<UploadedFile>> {
let uploaded_files = stream::iter(temp_files)
.map(|file| self.upload_and_remove(file, key_prefix))
// upload files concurrently, up to 2 at a time

View File

@ -56,7 +56,10 @@ async fn fetch_from_s3(
.await
.ok_or_else(|| error::ErrorNotFound("file with specified key not found"))?;
Ok(HttpResponse::Ok().body(SizedStream::new(file_size, file_stream)))
Ok(HttpResponse::Ok().body(SizedStream::new(
file_size,
tokio_util::io::ReaderStream::new(file_stream.into_async_read()),
)))
}
#[delete("/file/{s3_key}*")]