Skip to content

Commit

Permalink
Add oss
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Nov 14, 2024
1 parent 640dfba commit 04b7616
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ impl Access for OssBackend {
write_with_cache_control: true,
write_with_content_type: true,
write_with_content_disposition: true,
// TODO: set this to false while version has been enabled.
write_with_if_not_exists: true,

// The min multipart size of OSS is 100 KiB.
//
// ref: <https://www.alibabacloud.com/help/en/oss/user-guide/multipart-upload-12>
Expand Down
17 changes: 17 additions & 0 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ use serde::Deserialize;
use serde::Serialize;

use crate::raw::*;
use crate::services::oss::core::constants::X_OSS_FORBID_OVERWRITE;
use crate::*;

pub mod constants {
pub const X_OSS_SERVER_SIDE_ENCRYPTION: &str = "x-oss-server-side-encryption";

pub const X_OSS_SERVER_SIDE_ENCRYPTION_KEY_ID: &str = "x-oss-server-side-encryption-key-id";

pub const X_OSS_FORBID_OVERWRITE: &str = "x-oss-forbid-overwrite";

pub const RESPONSE_CONTENT_DISPOSITION: &str = "response-content-disposition";

pub const OSS_QUERY_VERSION_ID: &str = "versionId";
Expand Down Expand Up @@ -181,6 +184,20 @@ impl OssCore {
req = req.header(CACHE_CONTROL, cache_control);
}

// TODO: disable if not exists while version has been enabled.
//
// Specifies whether the object that is uploaded by calling the PutObject operation
// overwrites the existing object that has the same name. When versioning is enabled
// or suspended for the bucket to which you want to upload the object, the
// x-oss-forbid-overwrite header does not take effect. In this case, the object that
// is uploaded by calling the PutObject operation overwrites the existing object that
// has the same name.
//
// ref: https://www.alibabacloud.com/help/en/oss/developer-reference/putobject?spm=a2c63.p38356.0.0.39ef75e93o0Xtz
if args.if_not_exists() {
req = req.header(X_OSS_FORBID_OVERWRITE, "true");
}

if let Some(user_metadata) = args.user_metadata() {
for (key, value) in user_metadata {
// before insert user defined metadata header, add prefix to the header name
Expand Down

0 comments on commit 04b7616

Please sign in to comment.