datatrash/src/multipart.rs

22 lines
634 B
Rust
Raw Normal View History

2020-07-08 19:26:46 +00:00
use actix_multipart::Field;
use futures::StreamExt;
pub fn get_field_name(field: &Field) -> Result<String, actix_web::error::ParseError> {
field
.content_disposition()
.ok_or_else(|| actix_web::error::ParseError::Incomplete)?
.get_name()
.map(|s| s.to_owned())
.ok_or_else(|| actix_web::error::ParseError::Incomplete)
}
pub async fn read_string(
mut field: actix_multipart::Field,
) -> Result<String, std::string::FromUtf8Error> {
let mut data = Vec::new();
while let Some(chunk) = field.next().await {
data.extend(chunk.unwrap());
}
String::from_utf8(data)
}