This is an automated email from the ASF dual-hosted git repository.

Xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 976032b8f4 fix(services/b2): forward content type on presigned writes 
(#9091)
976032b8f4 is described below

commit 976032b8f46472416066d495d0c86be9066795e4
Author: Xuanwo <[email protected]>
AuthorDate: Thu Nov 26 02:13:39 2026 +0800

    fix(services/b2): forward content type on presigned writes (#9091)
    
    * fix(services/b2): forward content type on presigned writes
    
    * test(services/b2): verify presigned headers without uploading objects
---
 core/services/b2/src/backend.rs      |  5 +++--
 core/tests/behavior/async_presign.rs | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/core/services/b2/src/backend.rs b/core/services/b2/src/backend.rs
index eff99cd397..6dcc005187 100644
--- a/core/services/b2/src/backend.rs
+++ b/core/services/b2/src/backend.rs
@@ -437,7 +437,7 @@ impl Service for B2Backend {
                     parts.headers,
                 )))
             }
-            PresignOperation::Write(_) => {
+            PresignOperation::Write(write) => {
                 let resp = self.core.get_upload_url(ctx).await?;
 
                 let mut req = Request::post(&resp.upload_url);
@@ -447,7 +447,8 @@ impl Service for B2Backend {
                     "X-Bz-File-Name",
                     percent_encode_path(&build_absolute_path(&self.core.root, 
path)),
                 );
-                req = req.header(http::header::CONTENT_TYPE, "b2/x-auto");
+                let content_type = write.content_type().unwrap_or("b2/x-auto");
+                req = req.header(http::header::CONTENT_TYPE, content_type);
                 req = req.header(constants::X_BZ_CONTENT_SHA1, 
"do_not_verify");
 
                 let req = 
req.body(Buffer::new()).map_err(new_request_build_error)?;
diff --git a/core/tests/behavior/async_presign.rs 
b/core/tests/behavior/async_presign.rs
index 29f7601b5f..0d7a0719a3 100644
--- a/core/tests/behavior/async_presign.rs
+++ b/core/tests/behavior/async_presign.rs
@@ -50,6 +50,10 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
         tests.extend(async_trials!(op, test_presign_write_with_metadata));
     }
 
+    if op.info().scheme() == "b2" && cap.presign_write {
+        tests.extend(async_trials!(op, test_presign_write_b2_content_type));
+    }
+
     if op.info().scheme() == "swift" && cap.write && cap.presign_read {
         tests.extend(async_trials!(op, test_presign_read_with_range));
     }
@@ -154,6 +158,26 @@ async fn test_presign_write_with_metadata(op: Operator) -> 
Result<()> {
     Ok(())
 }
 
+async fn test_presign_write_b2_content_type(op: Operator) -> Result<()> {
+    let path = uuid::Uuid::new_v4().to_string();
+    let expire = Duration::from_secs(60);
+    let default_request = op.presign_write(&path, expire).await?;
+    assert_eq!(default_request.header()[header::CONTENT_TYPE], "b2/x-auto");
+
+    let request = op
+        .presign_write_options(
+            &path,
+            expire,
+            options::WriteOptions {
+                content_type: Some("application/json".to_owned()),
+                ..Default::default()
+            },
+        )
+        .await?;
+    assert_eq!(request.header()[header::CONTENT_TYPE], "application/json");
+    Ok(())
+}
+
 pub async fn test_presign_stat(op: Operator) -> Result<()> {
     let path = uuid::Uuid::new_v4().to_string();
     debug!("Generate a random file: {}", path);

Reply via email to