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

Updated forms/multipart-s3 to v4. (#505)

This commit is contained in:
Christopher Gubbin 2022-01-29 16:09:57 +00:00 committed by GitHub
parent 062a3af80c
commit 6e3ae0fd19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -2,18 +2,17 @@
name = "multipart-s3"
version = "0.1.0"
authors = ["cheolgyu <38715510+cheolgyu@users.noreply.github.com>"]
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "3"
actix-multipart = "0.3"
actix-web = "4.0.0-beta.21"
actix-multipart = "0.4.0-beta.12"
futures = "0.3.1"
rusoto_s3 = "0.43.0"
rusoto_core = "0.43.0"
bytes = { version = "0.5", features = ["serde"] }
rusoto_s3 = "0.47.0"
rusoto_core = "0.47.0"
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0"
dotenv = "0.15.0"
sanitize-filename = "0.2"
sanitize-filename = "0.3"

View File

@ -1,7 +1,6 @@
use crate::utils::s3::Client;
use actix_multipart::{Field, Multipart};
use actix_web::{web, Error};
use bytes::Bytes;
use actix_web::{web, web::Bytes, Error};
use futures::StreamExt;
use serde::{Deserialize, Serialize};
use std::convert::From;
@ -63,13 +62,13 @@ impl Tmpfile {
}
}
pub async fn split_payload(payload: &mut Multipart) -> (bytes::Bytes, Vec<Tmpfile>) {
pub async fn split_payload(payload: &mut Multipart) -> (Bytes, Vec<Tmpfile>) {
let mut tmp_files: Vec<Tmpfile> = Vec::new();
let mut data = Bytes::new();
while let Some(item) = payload.next().await {
let mut field: Field = item.expect(" split_payload err");
let content_type = field.content_disposition().unwrap();
let content_type = field.content_disposition();
let name = content_type.get_name().unwrap();
if name == "data" {
while let Some(chunk) = field.next().await {
@ -82,11 +81,13 @@ pub async fn split_payload(payload: &mut Multipart) -> (bytes::Bytes, Vec<Tmpfil
let tmp_path = tmp_file.tmp_path.clone();
let mut f = web::block(move || std::fs::File::create(&tmp_path))
.await
.unwrap()
.unwrap();
while let Some(chunk) = field.next().await {
let data = chunk.unwrap();
f = web::block(move || f.write_all(&data).map(|_| f))
.await
.unwrap()
.unwrap();
}
tmp_files.push(tmp_file.clone());