Properly handle Content-Type
This commit is contained in:
@@ -131,14 +131,14 @@ fn save_uploaded_file(file: &SavedField) -> Result<Option<String>, plume_models:
|
||||
};
|
||||
|
||||
let bucket = CONFIG.s3.as_ref().unwrap().get_bucket();
|
||||
match &file.headers.content_type {
|
||||
Some(ct) => {
|
||||
bucket.put_object_with_content_type_blocking(&dest, &bytes, &ct.to_string())?;
|
||||
}
|
||||
None => {
|
||||
bucket.put_object_blocking(&dest, &bytes)?;
|
||||
}
|
||||
}
|
||||
let content_type = match &file.headers.content_type {
|
||||
Some(ct) => ct.to_string(),
|
||||
None => ContentType::from_extension(&ext)
|
||||
.unwrap_or(ContentType::Binary)
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
bucket.put_object_with_content_type_blocking(&dest, &bytes, &content_type)?;
|
||||
|
||||
Ok(Some(dest))
|
||||
}
|
||||
|
||||
+6
-4
@@ -269,13 +269,15 @@ pub fn plume_media_files(file: PathBuf) -> Option<CachedFile> {
|
||||
|
||||
#[cfg(feature="s3")]
|
||||
{
|
||||
let ct = file.extension()
|
||||
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy()))
|
||||
.unwrap_or(ContentType::Binary);
|
||||
|
||||
let data = CONFIG.s3.as_ref().unwrap().get_bucket()
|
||||
.get_object_blocking(format!("static/media/{}", file.to_string_lossy())).ok()?;
|
||||
|
||||
let ct = data.headers().get("content-type")
|
||||
.and_then(|x| ContentType::parse_flexible(&x))
|
||||
.or_else(|| file.extension()
|
||||
.and_then(|ext| ContentType::from_extension(&ext.to_string_lossy())))
|
||||
.unwrap_or(ContentType::Binary);
|
||||
|
||||
Some(CachedFile {
|
||||
inner: FileKind::S3 ( data.to_vec(), ct),
|
||||
cache_control: CacheControl(vec![CacheDirective::MaxAge(60 * 60 * 24 * 30)]),
|
||||
|
||||
Reference in New Issue
Block a user