making content_type work for more types
This commit is contained in:
parent
ab8126a619
commit
d1337b1a89
|
@ -273,12 +273,13 @@ impl HealthForm {
|
|||
}
|
||||
}
|
||||
|
||||
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 last = self.last_name.clone();
|
||||
let filename_noext = format!("{}_{}", first, last);
|
||||
let file_name = if let Some(file) = self.file.as_ref() {
|
||||
file.file_name.to_owned()
|
||||
let (file_name, content_type) = if let Some(file) = self.file.as_ref() {
|
||||
let content_type = file.content_type.clone().map(|m| m.to_string());
|
||||
(file.file_name.to_owned(), content_type)
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
@ -302,7 +303,7 @@ impl HealthForm {
|
|||
return None;
|
||||
}
|
||||
info!(?f, "File saved successfully");
|
||||
Some((filename, path))
|
||||
Some((filename, path, content_type.clone()))
|
||||
}
|
||||
Err(e) => {
|
||||
error!("{:?}: Probably a missing image", e);
|
||||
|
@ -318,9 +319,10 @@ impl HealthForm {
|
|||
info!("{first} {last} filled out a health form!");
|
||||
let email = self.build_email().await;
|
||||
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 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);
|
||||
// info!(?attachment);
|
||||
MultiPart::mixed()
|
||||
|
|
Loading…
Reference in a new issue