diff --git a/src/s3/builders/put_object.rs b/src/s3/builders/put_object.rs index 78b6176..e6beecf 100644 --- a/src/s3/builders/put_object.rs +++ b/src/s3/builders/put_object.rs @@ -52,6 +52,7 @@ pub struct CreateMultipartUpload { tags: Option>, retention: Option, legal_hold: bool, + content_type: Option, } impl CreateMultipartUpload { @@ -108,6 +109,11 @@ impl CreateMultipartUpload { self } + pub fn content_type(mut self, content_type: Option) -> Self { + self.content_type = content_type; + self + } + fn get_headers(&self) -> Result { object_write_args_headers( self.extra_headers.as_ref(), @@ -116,6 +122,7 @@ impl CreateMultipartUpload { self.tags.as_ref(), self.retention.as_ref(), self.legal_hold, + self.content_type.as_ref(), ) } @@ -376,6 +383,7 @@ pub struct UploadPart { retention: Option, legal_hold: bool, data: SegmentedBytes, + content_type: Option, // This is used only when this struct is used for PutObject. user_metadata: Option, @@ -452,6 +460,7 @@ impl UploadPart { self.tags.as_ref(), self.retention.as_ref(), self.legal_hold, + self.content_type.as_ref(), ) } @@ -597,6 +606,7 @@ fn object_write_args_headers( tags: Option<&HashMap>, retention: Option<&Retention>, legal_hold: bool, + content_type: Option<&String>, ) -> Result { let mut map = Multimap::new(); @@ -662,7 +672,10 @@ fn object_write_args_headers( if !map.contains_key("Content-Type") { map.insert( String::from("Content-Type"), - String::from("application/octet-stream"), + match content_type { + Some(content_type) => content_type.clone(), + None => String::from("application/octet-stream"), + }, ); } @@ -686,7 +699,7 @@ pub struct PutObjectContent { retention: Option, legal_hold: bool, part_size: Size, - content_type: String, + content_type: Option, // source data input_content: ObjectContent, @@ -713,7 +726,7 @@ impl PutObjectContent { retention: None, legal_hold: false, part_size: Size::Unknown, - content_type: String::from("application/octet-stream"), + content_type: None, content_stream: ContentStream::empty(), part_count: None, } @@ -770,7 +783,7 @@ impl PutObjectContent { } pub fn content_type(mut self, content_type: String) -> Self { - self.content_type = content_type; + self.content_type = Some(content_type); self } @@ -965,6 +978,7 @@ impl PutObjectContent { part_number: None, upload_id: None, data, + content_type: self.content_type.clone(), }) } @@ -990,6 +1004,7 @@ impl PutObjectContent { part_number: Some(part_number), upload_id: Some(upload_id.to_string()), data, + content_type: self.content_type.clone(), } } @@ -1023,6 +1038,7 @@ impl PutObjectContent { tags: self.tags.clone(), retention: self.retention.clone(), legal_hold: self.legal_hold, + content_type: self.content_type.clone(), } } } diff --git a/tests/tests.rs b/tests/tests.rs index 71407c7..5bfa247 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -17,6 +17,7 @@ use async_std::task; use bytes::Bytes; use chrono::Duration; use futures_util::Stream; +use http::header; use hyper::http::Method; use minio::s3::builders::{ObjectContent, ObjectToDelete}; @@ -339,6 +340,7 @@ impl ClientTest { &object_name, ObjectContent::new_from_stream(data_src, Some(*size)), ) + .content_type(String::from("image/jpeg")) .send() .await .unwrap(); @@ -351,6 +353,10 @@ impl ClientTest { .unwrap(); assert_eq!(resp.size, *size as usize); assert_eq!(resp.etag, etag); + assert_eq!( + resp.headers.get(header::CONTENT_TYPE).unwrap(), + "image/jpeg" + ); self.client .remove_object(&self.test_bucket, object_name.as_str()) .send()