1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// MinIO Rust Library for Amazon S3 Compatible Cloud Storage
// Copyright 2025 MinIO, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::s3::builders::{
ComposeObject, ComposeObjectBldr, ComposeObjectInternal, ComposeObjectInternalBldr,
ComposeSource, CopyObject, CopyObjectBldr, CopyObjectInternal, CopyObjectInternalBldr,
UploadPartCopy, UploadPartCopyBldr,
};
use crate::s3::client::MinioClient;
use crate::s3::error::ValidationErr;
use crate::s3::types::{BucketName, ObjectKey, UploadId};
impl MinioClient {
/// Creates a [`UploadPartCopy`] request builder.
/// See [UploadPartCopy](https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPartCopy.html) S3 API
///
/// To execute the request, call [`UploadPartCopy::send()`](crate::s3::types::S3Api::send),
/// which returns a [`Result`] containing a [`UploadPartCopyResponse`](crate::s3::response::UploadPartCopyResponse).
///
/// # Example
///
/// ```no_run
/// use minio::s3::MinioClient;
/// use minio::s3::creds::StaticProvider;
/// use minio::s3::http::BaseUrl;
/// use minio::s3::response::UploadPartCopyResponse;
/// use minio::s3::segmented_bytes::SegmentedBytes;
/// use minio::s3::types::S3Api;
/// use minio::s3::response_traits::HasObject;
///
/// #[tokio::main]
/// async fn main() {
/// let base_url = "http://localhost:9000/".parse::<BaseUrl>().unwrap();
/// let static_provider = StaticProvider::new("minioadmin", "minioadmin", None);
/// let client = MinioClient::new(base_url, Some(static_provider), None, None).unwrap();
/// let data1: SegmentedBytes = SegmentedBytes::from("aaaa".to_string());
/// todo!();
/// let resp: UploadPartCopyResponse = client
/// .upload_part_copy("bucket-name", "object-name", "upload-id-123")
/// .unwrap().build().send().await.unwrap();
/// println!("uploaded {}", resp.object().unwrap());
/// }
/// ```
pub fn upload_part_copy<B, O, U>(
&self,
bucket: B,
object: O,
upload_id: U,
) -> Result<UploadPartCopyBldr, ValidationErr>
where
B: TryInto<BucketName>,
B::Error: Into<ValidationErr>,
O: TryInto<ObjectKey>,
O::Error: Into<ValidationErr>,
U: TryInto<UploadId>,
U::Error: Into<ValidationErr>,
{
Ok(UploadPartCopy::builder()
.client(self.clone())
.bucket(bucket.try_into().map_err(Into::into)?)
.object(object.try_into().map_err(Into::into)?)
.upload_id(upload_id.try_into().map_err(Into::into)?))
}
/// Create a CopyObject request builder. This is a lower-level API that
/// performs a non-multipart object copy.
pub(crate) fn copy_object_internal(
&self,
bucket: BucketName,
object: ObjectKey,
) -> CopyObjectInternalBldr {
CopyObjectInternal::builder()
.client(self.clone())
.bucket(bucket)
.object(object)
}
/// Create a CopyObject request builder.
/// See [CopyObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html) S3 API
///
/// To execute the copy operation, call [`CopyObject::send()`](crate::s3::types::S3Api::send),
/// which returns a [`Result`] containing a [`CopyObjectResponse`](crate::s3::response::CopyObjectResponse).
///
/// The destination of the copy is specified via the `bucket` and `object` parameters of this function.
/// To specify the source object to be copied, call `.source(...)` on the returned [`CopyObject`] builder.
///
/// Internally, this function first performs a [`stat_object`](MinioClient::stat_object) call
/// to retrieve metadata about the source object. It then constructs a
/// [`compose_object`](MinioClient::compose_object) request to perform the actual copy.
///
/// # Arguments
///
/// - `bucket`: The name of the destination bucket.
/// - `object`: The key (name) of the destination object.
///
/// # Example
///
/// ```no_run
/// use minio::s3::MinioClient;
/// use minio::s3::creds::StaticProvider;
/// use minio::s3::http::BaseUrl;
/// use minio::s3::response::CopyObjectResponse;
/// use minio::s3::builders::CopySource;
/// use minio::s3::types::{BucketName, ObjectKey, S3Api};
/// use minio::s3::response_traits::HasVersion;
///
/// #[tokio::main]
/// async fn main() {
/// let base_url = "http://localhost:9000/".parse::<BaseUrl>().unwrap();
/// let static_provider = StaticProvider::new("minioadmin", "minioadmin", None);
/// let client = MinioClient::new(base_url, Some(static_provider), None, None).unwrap();
/// let resp: CopyObjectResponse = client
/// .copy_object("bucket-name-dst", "object-name-dst")
/// .unwrap()
/// .source(CopySource::builder().bucket(BucketName::new("bucket-name-src").unwrap()).object(ObjectKey::new("object-name-src").unwrap()).build())
/// .build().send().await.unwrap();
/// println!("copied the file from src to dst. New version: {:?}", resp.version_id());
/// }
/// ```
pub fn copy_object<B, O>(&self, bucket: B, object: O) -> Result<CopyObjectBldr, ValidationErr>
where
B: TryInto<BucketName>,
B::Error: Into<ValidationErr>,
O: TryInto<ObjectKey>,
O::Error: Into<ValidationErr>,
{
Ok(CopyObject::builder()
.client(self.clone())
.bucket(bucket.try_into().map_err(Into::into)?)
.object(object.try_into().map_err(Into::into)?))
}
/// Create a ComposeObjectInternal request builder. This is a higher-level API that
/// performs a multipart object compose.
pub(crate) fn compose_object_internal(
&self,
bucket: BucketName,
object: ObjectKey,
) -> ComposeObjectInternalBldr {
ComposeObjectInternal::builder()
.client(self.clone())
.bucket(bucket)
.object(object)
}
/// compose object is higher-level API that calls an internal compose object, and if that call fails,
/// it calls ['abort_multipart_upload`](MinioClient::abort_multipart_upload).
pub fn compose_object<B, O>(
&self,
bucket: B,
object: O,
sources: Vec<ComposeSource>,
) -> Result<ComposeObjectBldr, ValidationErr>
where
B: TryInto<BucketName>,
B::Error: Into<ValidationErr>,
O: TryInto<ObjectKey>,
O::Error: Into<ValidationErr>,
{
Ok(ComposeObject::builder()
.client(self.clone())
.bucket(bucket.try_into().map_err(Into::into)?)
.object(object.try_into().map_err(Into::into)?)
.sources(sources))
}
}