Fix upload seems broken in the new version.
@@ -63,6 +63,7 @@ where
let mut builder = None;
let mut map = None;
+ let mut files = Vec::new();
while let Some(mut field) = multipart.next_field().await? {
match field.name() {
@@ -80,17 +81,8 @@ where
);
}
_ => {
- let builder = match &mut builder {
- Some(builder) => builder,
- None => return Err(ParseRequestError::MissingOperatorsPart),
- };
- let map = match &mut map {
- Some(map) => map,
- None => return Err(ParseRequestError::MissingMapPart),
- };
- if let Some(name) = field.name() {
+ if let Some(name) = field.name().map(ToString::to_string) {
if let Some(filename) = field.file_name().map(ToString::to_string) {
- if let Some(var_paths) = map.remove(name) {
let content_type =
field.content_type().map(|mime| mime.to_string());
let mut file =
@@ -99,6 +91,24 @@ where
file.write(&chunk).map_err(ParseRequestError::Io)?;
}
file.seek(SeekFrom::Start(0))?;
+ files.push((name, filename, content_type, file));
+ }
+ }
+ }
+ }
+ }
+
+ let mut builder = match builder {
+ Some(builder) => builder,
+ None => return Err(ParseRequestError::MissingOperatorsPart),
+ };
+ let map = match &mut map {
+ Some(map) => map,
+ None => return Err(ParseRequestError::MissingMapPart),
+ };
+
+ for (name, filename, content_type, file) in files {
+ if let Some(var_paths) = map.remove(&name) {
for var_path in var_paths {
builder.set_upload(
&var_path,
@@ -109,23 +119,12 @@ where
}
}
}
- }
- }
- }
- }
- if let Some(map) = &map {
if !map.is_empty() {
return Err(ParseRequestError::MissingFiles);
}
- } else {
- return Err(ParseRequestError::MissingMapPart);
- }
- Ok(match builder {
- Some(builder) => builder,
- None => return Err(ParseRequestError::MissingOperatorsPart),
- })
+ Ok(builder)
} else {
let mut data = Vec::new();
self.1
