2525sys .setdefaultencoding ('utf-8' )
2626maplist = {
2727 'ContentLength' : 'Content-Length' ,
28- 'ContentType' : 'Content-Type' ,
2928 'ContentMD5' : 'Content-MD5' ,
29+ 'ContentType' : 'Content-Type' ,
3030 'CacheControl' : 'Cache-Control' ,
3131 'ContentDisposition' : 'Content-Disposition' ,
3232 'ContentEncoding' : 'Content-Encoding' ,
33+ 'ContentLanguage' : 'Content-Language' ,
3334 'Expires' : 'Expires' ,
35+ 'ResponseContentType' : 'response-content-type' ,
36+ 'ResponseContentLanguage' : 'response-content-language' ,
37+ 'ResponseExpires' : 'response-expires' ,
38+ 'ResponseCacheControl' : 'response-cache-control' ,
39+ 'ResponseContentDisposition' : 'response-content-disposition' ,
40+ 'ResponseContentEncoding' : 'response-content-encoding' ,
3441 'Metadata' : 'Metadata' ,
3542 'ACL' : 'x-cos-acl' ,
3643 'GrantFullControl' : 'x-cos-grant-full-control' ,
3744 'GrantWrite' : 'x-cos-grant-write' ,
3845 'GrantRead' : 'x-cos-grant-read' ,
3946 'StorageClass' : 'x-cos-storage-class' ,
40- 'EncodingType' : 'encoding-type'
47+ 'Range' : 'Range' ,
48+ 'IfMatch' : 'If-Match' ,
49+ 'IfNoneMatch' : 'If-None-Match' ,
50+ 'IfModifiedSince' : 'If-Modified-Since' ,
51+ 'IfUnmodifiedSince' : 'If-Unmodified-Since' ,
52+ 'VersionId' : 'x-cos-version-id' ,
4153 }
4254
4355
@@ -320,6 +332,11 @@ def copy_object(self, Bucket, Key, CopySource, CopyStatus='Copy', **kwargs):
320332 def create_multipart_upload (self , Bucket , Key , ** kwargs ):
321333 """创建分片上传,适用于大文件上传"""
322334 headers = mapped (kwargs )
335+ if 'Metadata' in headers .keys ():
336+ for i in headers ['Metadata' ].keys ():
337+ headers [i ] = headers ['Metadata' ][i ]
338+ headers .pop ('Metadata' )
339+
323340 url = self ._conf .uri (bucket = Bucket , path = Key + "?uploads" )
324341 logger .info ("create multipart upload, url=:{url} ,headers=:{headers}" .format (
325342 url = url ,
@@ -383,18 +400,25 @@ def abort_multipart_upload(self, Bucket, Key, UploadId, **kwargs):
383400 headers = headers )
384401 return None
385402
386- def list_parts (self , Bucket , Key , UploadId , ** kwargs ):
403+ def list_parts (self , Bucket , Key , UploadId , EncodingType = 'url' , MaxParts = 1000 , PartNumberMarker = 0 , ** kwargs ):
387404 """列出已上传的分片"""
388405 headers = mapped (kwargs )
389- url = self ._conf .uri (bucket = Bucket , path = Key + "?uploadId={UploadId}" .format (UploadId = UploadId ))
406+ params = {
407+ 'uploadId' : UploadId ,
408+ 'part-number-marker' : PartNumberMarker ,
409+ 'max-parts' : MaxParts ,
410+ 'encoding-type' : EncodingType }
411+
412+ url = self ._conf .uri (bucket = Bucket , path = Key )
390413 logger .info ("list multipart upload, url=:{url} ,headers=:{headers}" .format (
391414 url = url ,
392415 headers = headers ))
393416 rt = self .send_request (
394417 method = 'GET' ,
395418 url = url ,
396419 auth = CosS3Auth (self ._conf ._access_id , self ._conf ._access_key ),
397- headers = headers )
420+ headers = headers ,
421+ params = params )
398422 data = xml_to_dict (rt .text )
399423 if 'Part' in data .keys () and isinstance (data ['Part' ], dict ): # 只有一个part,将dict转为list,保持一致
400424 lst = []
@@ -464,7 +488,7 @@ def delete_bucket(self, Bucket, **kwargs):
464488 headers = headers )
465489 return None
466490
467- def list_objects (self , Bucket , Delimiter = "" , Marker = "" , MaxKeys = 1000 , Prefix = "" , ** kwargs ):
491+ def list_objects (self , Bucket , Delimiter = "" , Marker = "" , MaxKeys = 1000 , Prefix = "" , EncodingType = "url" , ** kwargs ):
468492 """获取文件列表"""
469493 headers = mapped (kwargs )
470494 url = self ._conf .uri (bucket = Bucket )
@@ -475,7 +499,8 @@ def list_objects(self, Bucket, Delimiter="", Marker="", MaxKeys=1000, Prefix="",
475499 'delimiter' : Delimiter ,
476500 'marker' : Marker ,
477501 'max-keys' : MaxKeys ,
478- 'prefix' : Prefix }
502+ 'prefix' : Prefix ,
503+ 'encoding-type' : EncodingType }
479504 rt = self .send_request (
480505 method = 'GET' ,
481506 url = url ,
0 commit comments