Support for PostObject #222
1 changed files with 187 additions and 184 deletions
|
@ -43,7 +43,14 @@ pub async fn handle_post_object(
|
||||||
let mut multipart = Multipart::with_constraints(body, boundary, constraints);
|
let mut multipart = Multipart::with_constraints(body, boundary, constraints);
|
||||||
|
|
||||||
let mut params = HeaderMap::new();
|
let mut params = HeaderMap::new();
|
||||||
while let Some(field) = multipart.next_field().await? {
|
let field = loop {
|
||||||
trinity-1686a marked this conversation as resolved
Outdated
|
|||||||
|
let field = if let Some(field) = multipart.next_field().await? {
|
||||||
|
field
|
||||||
|
} else {
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
"Request did not contain a file".to_owned(),
|
||||||
|
));
|
||||||
|
};
|
||||||
let name: HeaderName = if let Some(Ok(name)) = field.name().map(TryInto::try_into) {
|
let name: HeaderName = if let Some(Ok(name)) = field.name().map(TryInto::try_into) {
|
||||||
name
|
name
|
||||||
} else {
|
} else {
|
||||||
|
@ -62,8 +69,10 @@ pub async fn handle_post_object(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
} else {
|
||||||
|
break field;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Current part is file. Do some checks before handling to PutObject code
|
// Current part is file. Do some checks before handling to PutObject code
|
||||||
let key = params
|
let key = params
|
||||||
|
@ -235,7 +244,6 @@ pub async fn handle_post_object(
|
||||||
.and_then(|h| h.to_str().ok())
|
.and_then(|h| h.to_str().ok())
|
||||||
.unwrap_or("204");
|
.unwrap_or("204");
|
||||||
let builder = Response::builder()
|
let builder = Response::builder()
|
||||||
.status(StatusCode::OK)
|
|
||||||
.header(header::LOCATION, location)
|
.header(header::LOCATION, location)
|
||||||
.header(header::ETAG, etag);
|
.header(header::ETAG, etag);
|
||||||
match action {
|
match action {
|
||||||
|
@ -248,12 +256,7 @@ pub async fn handle_post_object(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(resp);
|
Ok(resp)
|
||||||
}
|
|
||||||
|
|
||||||
Err(Error::BadRequest(
|
|
||||||
"Request did not contain a file".to_owned(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
Loading…
Reference in a new issue
I think we can avoid putting almost the entire code of this function in the
while
loop (and remove 1 indentation level almost everywhere) by doing something like this:This looks much nicer to me, especially as in the current version we have a
for
inside thewhile
, which looks a bit like a nested loop but is in fact not at all.