diff --git a/tardis/Cargo.toml b/tardis/Cargo.toml index 8d65948..c570487 100644 --- a/tardis/Cargo.toml +++ b/tardis/Cargo.toml @@ -50,7 +50,7 @@ ws-client = ["future", "tokio-tungstenite", "tls"] cache = ["futures-util", "redis", "deadpool-redis"] mq = ["futures-util", "lapin", "amq-protocol-types", "async-global-executor"] mail = ["lettre"] -os = ["async-trait", "anyhow", "rust-s3"] +os = ["async-trait", "anyhow", "rust-s3", "urlencoding"] k8s = ["future", "kube", "k8s-openapi"] fs = ["tokio/fs", "tokio/io-util"] process = ["tokio/process"] @@ -85,6 +85,7 @@ url = { version = "2.2", features = ["serde"] } lru = { version = "0.12.0" } typed-builder = { version = "0.18" } paste = { version = "1.0" } +urlencoding = { version = "2" , optional = true } # Tokio tokio = { version = "1", features = [ "macros", diff --git a/tardis/src/os/os_client.rs b/tardis/src/os/os_client.rs index a7db57f..9257523 100644 --- a/tardis/src/os/os_client.rs +++ b/tardis/src/os/os_client.rs @@ -297,7 +297,7 @@ impl TardisOSOperations for TardisOSS3Client { async fn object_copy(&self, from: &str, to: &str, bucket_name: Option<&str>) -> TardisResult<()> { let bucket = self.get_bucket(bucket_name)?; - bucket.copy_object_internal(from, to).await?; + bucket.copy_object_internal(urlencoding::encode(from), to).await?; Ok(()) } diff --git a/tardis/tests/test_os_client.rs b/tardis/tests/test_os_client.rs index 13883ed..0f11fac 100644 --- a/tardis/tests/test_os_client.rs +++ b/tardis/tests/test_os_client.rs @@ -25,7 +25,8 @@ async fn test_os_client() -> TardisResult<()> { let data = TardisFuns::os().object_get("test/test.txt", Some(bucket_name)).await?; assert_eq!(String::from_utf8(data).unwrap(), "I want to go to S3 测试"); - TardisFuns::os().object_copy("test/test.txt", "test/test_cp.txt", Some(bucket_name)).await?; + TardisFuns::os().object_copy("test/test.txt", "test/test复制.txt", Some(bucket_name)).await?; + TardisFuns::os().object_copy("test/test复制.txt", "test/test_cp.txt", Some(bucket_name)).await?; let data = TardisFuns::os().object_get("test/test_cp.txt", Some(bucket_name)).await?; assert_eq!(String::from_utf8(data).unwrap(), "I want to go to S3 测试"); @@ -41,6 +42,7 @@ async fn test_os_client() -> TardisResult<()> { assert_eq!(String::from_utf8(data).unwrap(), "I want to go to S3 测试"); TardisFuns::os().object_delete("test/test.txt", Some(bucket_name)).await?; + TardisFuns::os().object_delete("test/test复制.txt", Some(bucket_name)).await?; TardisFuns::os().object_delete("test/test_cp.txt", Some(bucket_name)).await?; assert!(TardisFuns::os().object_get("test/test.txt", Some(bucket_name)).await.is_err());