Skip to content

Commit

Permalink
Added a parameter that can set the head (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
lewzylu authored Apr 9, 2018
1 parent 7678cf8 commit 2dbc2f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
11 changes: 7 additions & 4 deletions coscmd/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def upload_folder(self, local_path, cos_path, _type='Standard', _encryption='',
logger.debug("upload {file} success".format(file=to_printable_str(filepath)))
return ret_code

def upload_file(self, local_path, cos_path, _type='Standard', _encryption='', _http_headers=''):
def upload_file(self, local_path, cos_path, _type='Standard', _encryption='', _http_headers='{}'):

_http_header = yaml.safe_load(_http_headers)

Expand All @@ -262,7 +262,8 @@ def single_upload():
for j in range(self._retry):
try:
http_header = _http_header
http_header['x-cos-storage-class'] = self._type
if http_header is None or http_header.has_key('x-cos-storage-class') is False:
http_header['x-cos-storage-class'] = self._type
if _encryption != '':
http_header['x-cos-server-side-encryption'] = self._encryption
rt = self._session.put(url=url,
Expand All @@ -280,7 +281,8 @@ def single_upload():
continue
if j+1 == self._retry:
return False
except Exception:
except Exception, e:
logger.warn(e)
logger.warn("upload file failed")
return False

Expand All @@ -301,7 +303,8 @@ def init_multiupload():
logger.info("continue uploading from last breakpoint")
return True
http_header = _http_header
http_header['x-cos-storage-class'] = self._type
if http_header is None or http_header.has_key('x-cos-storage-class') is False:
http_header['x-cos-storage-class'] = self._type
if _encryption != '':
http_header['x-cos-server-side-encryption'] = self._encryption
rt = self._session.post(url=url+"?uploads", auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key), headers=http_header)
Expand Down
2 changes: 1 addition & 1 deletion coscmd/cos_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def command_thread():
parser_upload.add_argument('-r', '--recursive', help="upload recursively when upload directory", action="store_true", default=False)
parser_upload.add_argument('-t', '--type', help='specify x-cos-storage-class of files to upload', type=str, choices=['STANDARD', 'STANDARD_IA', 'NEARLINE'], default='STANDARD')
parser_upload.add_argument('-e', '--encryption', help="set encryption", type=str, default='')
parser_upload.add_argument('-H', '--headers', help="set HTTP headers", type=str, default='')
parser_upload.add_argument('-H', '--headers', help="set HTTP headers", type=str, default='{}')
parser_upload.set_defaults(func=Op.upload)

parser_download = sub_parser.add_parser("download", help="download file from COS to local.")
Expand Down
13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
requests>=2.12.4
argparse>=1.4.0
prettytable==0.7
pytz==2017.2
datetime==4.2
tqdm==4.15.0
requests>=2.12.4
argparse>=1.4.0
prettytable==0.7
pytz==2017.2
datetime==4.2
tqdm==4.15.0
pyyaml==3.12

0 comments on commit 2dbc2f8

Please sign in to comment.