mirror of
https://github.com/minio/minio-rs.git
synced 2025-12-06 15:26:51 +08:00
Respect content_type prop (#100)
This commit is contained in:
parent
b254b2f7ae
commit
2ce4fefbc3
@ -52,6 +52,7 @@ pub struct CreateMultipartUpload {
|
||||
tags: Option<HashMap<String, String>>,
|
||||
retention: Option<Retention>,
|
||||
legal_hold: bool,
|
||||
content_type: Option<String>,
|
||||
}
|
||||
|
||||
impl CreateMultipartUpload {
|
||||
@ -108,6 +109,11 @@ impl CreateMultipartUpload {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn content_type(mut self, content_type: Option<String>) -> Self {
|
||||
self.content_type = content_type;
|
||||
self
|
||||
}
|
||||
|
||||
fn get_headers(&self) -> Result<Multimap, Error> {
|
||||
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<Retention>,
|
||||
legal_hold: bool,
|
||||
data: SegmentedBytes,
|
||||
content_type: Option<String>,
|
||||
|
||||
// This is used only when this struct is used for PutObject.
|
||||
user_metadata: Option<Multimap>,
|
||||
@ -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<String, String>>,
|
||||
retention: Option<&Retention>,
|
||||
legal_hold: bool,
|
||||
content_type: Option<&String>,
|
||||
) -> Result<Multimap, Error> {
|
||||
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<Retention>,
|
||||
legal_hold: bool,
|
||||
part_size: Size,
|
||||
content_type: String,
|
||||
content_type: Option<String>,
|
||||
|
||||
// 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user