same for mt-form
This commit is contained in:
parent
d1337b1a89
commit
2951571d5a
|
@ -289,12 +289,13 @@ impl MtForm {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_temp_file(&mut self) -> Option<(String, String)> {
|
fn get_temp_file(&mut self) -> Option<(String, String, Option<String>)> {
|
||||||
let first = self.first_name.clone();
|
let first = self.first_name.clone();
|
||||||
let last = self.last_name.clone();
|
let last = self.last_name.clone();
|
||||||
let filename_noext = format!("{}_{}", first, last);
|
let filename_noext = format!("{}_{}", first, last);
|
||||||
let file_name = if let Some(file) = self.file.as_ref() {
|
let (file_name, content_type) = if let Some(file) = self.file.as_ref() {
|
||||||
file.file_name.to_owned()
|
let content_type = file.content_type.clone().map(|m| m.to_string());
|
||||||
|
(file.file_name.to_owned(), content_type)
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
@ -318,7 +319,7 @@ impl MtForm {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
info!(?f, "File saved successfully");
|
info!(?f, "File saved successfully");
|
||||||
Some((filename, path))
|
Some((filename, path, content_type.clone()))
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("{:?}: Probably a missing image", e);
|
error!("{:?}: Probably a missing image", e);
|
||||||
|
@ -334,9 +335,10 @@ impl MtForm {
|
||||||
info!("{first} {last} signed up for mission trip!");
|
info!("{first} {last} signed up for mission trip!");
|
||||||
let email = self.build_email().await;
|
let email = self.build_email().await;
|
||||||
let temp_file = self.get_temp_file();
|
let temp_file = self.get_temp_file();
|
||||||
let multi = if let Some((file, path)) = temp_file {
|
let multi = if let Some((file, path, content_type)) = temp_file {
|
||||||
let filebody = fs::read(path);
|
let filebody = fs::read(path);
|
||||||
let content_type = ContentType::parse("image/jpg").unwrap();
|
let content_type =
|
||||||
|
ContentType::parse(&content_type.unwrap_or(String::from("image/jpg"))).unwrap();
|
||||||
let attachment = Attachment::new(file).body(filebody.unwrap(), content_type);
|
let attachment = Attachment::new(file).body(filebody.unwrap(), content_type);
|
||||||
// info!(?attachment);
|
// info!(?attachment);
|
||||||
MultiPart::mixed()
|
MultiPart::mixed()
|
||||||
|
|
Loading…
Reference in a new issue