Skip to content

Commit ab32a45

Browse files
authored
feat: add CopyObject (#22)
1 parent 91c9715 commit ab32a45

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

cloud/object_storage/alicloud_object_storage.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ func (service *AliCloudObjectStorageService) DeleteObjects(ctx context.Context,
325325
return err
326326
}
327327

328+
func (service *AliCloudObjectStorageService) CopyObject(ctx context.Context, from, to string) error {
329+
if from == "" || to == "" {
330+
return ErrObjectKeyEmpty
331+
}
332+
bucket, err := service.client.Bucket(service.bucketName)
333+
if err != nil {
334+
return err
335+
}
336+
if _, err := bucket.CopyObject(from, to); err != nil {
337+
return err
338+
}
339+
return nil
340+
}
341+
328342
func (service *AliCloudObjectStorageService) GetSignedURL(key string, duration time.Duration) (string, error) {
329343
if key == "" {
330344
return "", ErrObjectKeyEmpty

cloud/object_storage/aws_object_storage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ func (service *AWSObjectStorageService) DeleteObjects(ctx context.Context, keys
200200
return err
201201
}
202202

203+
func (service *AWSObjectStorageService) CopyObject(ctx context.Context, from, to string) error {
204+
if from == "" || to == "" {
205+
return ErrObjectKeyEmpty
206+
}
207+
_, err := service.client.CopyObjectWithContext(ctx, &s3.CopyObjectInput{
208+
Bucket: aws.String(service.bucketName),
209+
CopySource: aws.String(from),
210+
Key: aws.String(to),
211+
})
212+
return err
213+
}
214+
203215
func (service *AWSObjectStorageService) GetSignedURL(key string, duration time.Duration) (string, error) {
204216
if key == "" {
205217
return "", ErrObjectKeyEmpty

cloud/object_storage/object_storage.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ObjectStorageService interface {
2727
PutObject(ctx context.Context, key string, input *PutObjectInput) error
2828
DeleteObject(ctx context.Context, key string) error
2929
DeleteObjects(ctx context.Context, keys ...string) error
30+
CopyObject(ctx context.Context, from, to string) error
3031
GetSignedURL(key string, duration time.Duration) (string, error)
3132
// GetSignedURLForExistedKey generates signed url if key exists. If key does not exist, return error
3233
GetSignedURLForExistedKey(ctx context.Context, key string, duration time.Duration) (string, error)
@@ -128,7 +129,6 @@ type PutHeaderOption struct {
128129
}
129130

130131
func (o *PutHeaderOption) ToAliCloudOptions() []oss.Option {
131-
132132
options := make([]oss.Option, 0)
133133
if o.ContentDisposition != nil {
134134
options = append(options, oss.ContentDisposition(*o.ContentDisposition))
@@ -152,7 +152,6 @@ func (o *PutHeaderOption) ToAliCloudOptions() []oss.Option {
152152
}
153153

154154
func (o *PutHeaderOption) ToTencentCloudOptions() *cos.PresignedURLOptions {
155-
156155
opt := &cos.PresignedURLOptions{
157156
Query: &url.Values{},
158157
Header: &http.Header{},

cloud/object_storage/tencentcloud_object_storage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ func (service *TencentCloudObjectStorageService) DeleteObjects(ctx context.Conte
272272
return err
273273
}
274274

275+
func (service *TencentCloudObjectStorageService) CopyObject(ctx context.Context, from, to string) error {
276+
if from == "" || to == "" {
277+
return ErrObjectKeyEmpty
278+
}
279+
_, _, err := service.client.Object.Copy(ctx, to, from, nil)
280+
return err
281+
}
282+
275283
func (service *TencentCloudObjectStorageService) GetSignedURL(key string, duration time.Duration) (string, error) {
276284
if key == "" {
277285
return "", ErrObjectKeyEmpty

0 commit comments

Comments
 (0)