From d1337b1a89a8e98a90cc0062fe59596e0ad1d6b4 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 19 Dec 2024 12:15:53 -0600 Subject: [PATCH] making content_type work for more types --- src/api/health_form.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/health_form.rs b/src/api/health_form.rs index 7e38071..5f5f589 100644 --- a/src/api/health_form.rs +++ b/src/api/health_form.rs @@ -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)> { 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()