Skip to content

Commit abf923a

Browse files
committed
Modify Copy Object
1 parent 8e6200f commit abf923a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Diff for: qcloud_cos/cos_client.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,31 @@ def head_object(self, Bucket, Key, **kwargs):
319319

320320
def gen_copy_source_url(self, CopySource):
321321
"""拼接拷贝源url"""
322+
if 'Appid' in CopySource.keys():
323+
appid = CopySource['Appid']
324+
else:
325+
raise CosClientError('CopySource Need Parameter Appid')
322326
if 'Bucket' in CopySource.keys():
323327
bucket = CopySource['Bucket']
324328
else:
325329
raise CosClientError('CopySource Need Parameter Bucket')
330+
if 'Region' in CopySource.keys():
331+
region = CopySource['Region']
332+
region = format_region(region)
333+
else:
334+
raise CosClientError('CopySource Need Parameter Region')
326335
if 'Key' in CopySource.keys():
327-
key = CopySource['Key']
336+
path = CopySource['Key']
337+
if path and path[0] == '/':
338+
path = path[1:]
328339
else:
329340
raise CosClientError('CopySource Need Parameter Key')
330-
url = self._conf.uri(bucket=bucket, path=key).encode('utf8')
331-
url = url[7:] # copysource不支持http://开头,去除
341+
url = "{bucket}-{uid}.{region}.myqcloud.com/{path}".format(
342+
bucket=bucket,
343+
uid=appid,
344+
region=region,
345+
path=path
346+
)
332347
return url
333348

334349
def copy_object(self, Bucket, Key, CopySource, CopyStatus='Copy', **kwargs):

Diff for: qcloud_cos/test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def Test():
6060
print "Test List Buckets"
6161
response = client.list_buckets()
6262

63-
copy_source = {'Bucket': 'test01', 'Key': '/test.txt'}
63+
copy_source = {'Appid': '1252408340', 'Bucket': 'test02', 'Key': '/test.txt', 'Region': 'ap-guangzhou'}
6464
print "Test Copy Object From Other Bucket "
6565

6666
response = client.copy_object(

0 commit comments

Comments
 (0)