forked from neri/datatrash
22 lines
634 B
Rust
22 lines
634 B
Rust
|
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)
|
||
|
}
|