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 7bb32c522e fix(services/b2): forward user metadata in presigned
uploads (#9295)
7bb32c522e is described below
commit 7bb32c522ed74cfb246387769f666733b41bfaf2
Author: Xuanwo <[email protected]>
AuthorDate: Sat Nov 28 00:31:29 2026 +0800
fix(services/b2): forward user metadata in presigned uploads (#9295)
---
core/services/b2/src/backend.rs | 9 +++++++++
core/tests/behavior/async_presign.rs | 15 +++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/core/services/b2/src/backend.rs b/core/services/b2/src/backend.rs
index 6c1994b38b..927206a806 100644
--- a/core/services/b2/src/backend.rs
+++ b/core/services/b2/src/backend.rs
@@ -614,6 +614,15 @@ impl Service for B2Backend {
req = req.header(http::header::CONTENT_TYPE, content_type);
req = req.header(constants::X_BZ_CONTENT_SHA1,
"do_not_verify");
+ if let Some(user_metadata) = write.user_metadata() {
+ for (key, value) in user_metadata {
+ req = req.header(
+ format!("{}{}", constants::X_BZ_INFO_PREFIX, key),
+ percent_encode_path(value),
+ );
+ }
+ }
+
let req =
req.body(Buffer::new()).map_err(new_request_build_error)?;
// We don't need this request anymore, consume it directly.
let (parts, _) = req.into_parts();
diff --git a/core/tests/behavior/async_presign.rs
b/core/tests/behavior/async_presign.rs
index 0d7a0719a3..696598bf21 100644
--- a/core/tests/behavior/async_presign.rs
+++ b/core/tests/behavior/async_presign.rs
@@ -51,7 +51,7 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
}
if op.info().scheme() == "b2" && cap.presign_write {
- tests.extend(async_trials!(op, test_presign_write_b2_content_type));
+ tests.extend(async_trials!(op, test_presign_write_b2_headers));
}
if op.info().scheme() == "swift" && cap.write && cap.presign_read {
@@ -158,7 +158,7 @@ async fn test_presign_write_with_metadata(op: Operator) ->
Result<()> {
Ok(())
}
-async fn test_presign_write_b2_content_type(op: Operator) -> Result<()> {
+async fn test_presign_write_b2_headers(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?;
@@ -170,11 +170,22 @@ async fn test_presign_write_b2_content_type(op: Operator)
-> Result<()> {
expire,
options::WriteOptions {
content_type: Some("application/json".to_owned()),
+ user_metadata: Some(
+ [(
+ "application-validation".to_owned(),
+ "b2 trial + café %".to_owned(),
+ )]
+ .into(),
+ ),
..Default::default()
},
)
.await?;
assert_eq!(request.header()[header::CONTENT_TYPE], "application/json");
+ assert_eq!(
+ request.header()["x-bz-info-application-validation"],
+ "b2%20trial%20%2B%20caf%C3%A9%20%25"
+ );
Ok(())
}