diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs index 37ba515457c7..ffd76a4a8464 100644 --- a/core/src/services/azblob/core.rs +++ b/core/src/services/azblob/core.rs @@ -16,6 +16,7 @@ // under the License. use bytes::Bytes; +use http::header::HeaderName; use http::header::CONTENT_LENGTH; use http::header::CONTENT_TYPE; use http::header::IF_MATCH; @@ -23,7 +24,6 @@ use http::header::IF_NONE_MATCH; use http::HeaderValue; use http::Request; use http::Response; -use http::{header::HeaderName, StatusCode}; use reqsign::AzureStorageCredential; use reqsign::AzureStorageLoader; use reqsign::AzureStorageSigner; @@ -39,8 +39,6 @@ use uuid::Uuid; use crate::raw::*; use crate::*; -use super::error::parse_error; - mod constants { pub const X_MS_VERSION: &str = "x-ms-version"; @@ -381,6 +379,7 @@ impl AzblobCore { args: &OpWrite, body: AsyncBody, ) -> Result> { + // refer to https://learn.microsoft.com/en-us/rest/api/storageservices/put-block-list? let p = build_abs_path(&self.root, path); let url = format!( @@ -439,16 +438,16 @@ impl AzblobCore { let req = self.insert_sse_headers(req); // Set body - let mut req_body = "".to_string(); - req_body.push_str("\n"); + let req_body = { + let block_list = block_ids + .iter() + .map(|block_id| format!(" {}", block_id)) + .collect::>() + .join("\n"); - for block_id in block_ids { - req_body.push_str(""); - req_body.push_str(&block_id.to_string()); - req_body.push_str("\n"); - } + format!("\n{}\n", block_list) + }; - req_body.push_str(""); let body = AsyncBody::Bytes(Bytes::from(req_body.to_string())); let req = req.body(body).map_err(new_request_build_error)?; Ok(req) diff --git a/core/src/services/azblob/writer.rs b/core/src/services/azblob/writer.rs index fca2cf458bf8..fceba0f1e5d2 100644 --- a/core/src/services/azblob/writer.rs +++ b/core/src/services/azblob/writer.rs @@ -43,34 +43,6 @@ impl AzblobWriter { } } -#[cfg_attr(not(target_arch = "wasm32"), async_trait)] -#[cfg_attr(target_arch = "wasm32", async_trait(?Send))] -impl oio::OneShotWrite for AzblobWriter { - async fn write_once(&self, bs: &dyn oio::WriteBuf) -> Result<()> { - let bs = oio::ChunkedBytes::from_vec(bs.vectored_bytes(bs.remaining())); - let mut req = self.core.azblob_put_blob_request( - &self.path, - Some(bs.len() as u64), - &self.op, - AsyncBody::ChunkedBytes(bs), - )?; - - self.core.sign(&mut req).await?; - - let resp = self.core.send(req).await?; - - let status = resp.status(); - - match status { - StatusCode::CREATED | StatusCode::OK => { - resp.into_body().consume().await?; - Ok(()) - } - _ => Err(parse_error(resp).await?), - } - } -} - #[cfg_attr(not(target_arch = "wasm32"), async_trait)] #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] impl oio::AppendWrite for AzblobWriter {