Skip to content

Commit

Permalink
Complete #940 - upload_id, content_disposition and content_type defau…
Browse files Browse the repository at this point in the history
…lt value is now "" and not anymore None
  • Loading branch information
fviard committed Mar 3, 2018
1 parent a455532 commit d07bcfa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Config(object):
enable = None
get_continue = False
put_continue = False
upload_id = None
upload_id = u""
skip_existing = False
recursive = False
restore_days = 1
Expand Down Expand Up @@ -189,8 +189,8 @@ class Config(object):
limitrate = 0
requester_pays = False
stop_on_error = False
content_disposition = None
content_type = None
content_disposition = u""
content_type = u""
stats = False
# Disabled by default because can create a latency with a CONTINUE status reply
# expected for every send file requests.
Expand Down
8 changes: 4 additions & 4 deletions S3/Crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,19 @@ def sign_url_base_v2(**parms):
debug("Expiry interpreted as epoch time %s", parms['expiry'])
signtext = 'GET\n\n\n%(expiry)d\n/%(bucket)s/%(object)s' % parms
param_separator = '?'
if content_disposition is not None:
if content_disposition:
signtext += param_separator + 'response-content-disposition=' + content_disposition
param_separator = '&'
if content_type is not None:
if content_type:
signtext += param_separator + 'response-content-type=' + content_type
param_separator = '&'
debug("Signing plaintext: %r", signtext)
parms['sig'] = s3_quote(sign_string_v2(encode_to_s3(signtext)), unicode_output=True)
debug("Urlencoded signature: %s", parms['sig'])
url = "%(proto)s://%(bucket)s.%(host_base)s/%(object)s?AWSAccessKeyId=%(access_key)s&Expires=%(expiry)d&Signature=%(sig)s" % parms
if content_disposition is not None:
if content_disposition:
url += "&response-content-disposition=" + s3_quote(content_disposition, unicode_output=True)
if content_type is not None:
if content_type:
url += "&response-content-type=" + s3_quote(content_type, unicode_output=True)
return url

Expand Down
10 changes: 5 additions & 5 deletions S3/MultiPart.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_parts_information(self, uri, upload_id):
return parts

def get_unique_upload_id(self, uri):
upload_id = None
upload_id = ""
multipart_response = self.s3.get_multipart(uri)
tree = getTreeFromXml(multipart_response['data'])
for mpupload in parseNodes(tree):
Expand All @@ -49,7 +49,7 @@ def get_unique_upload_id(self, uri):
mp_path = mpupload['Key']
info("mp_path: %s, object: %s" % (mp_path, uri.object()))
if mp_path == uri.object():
if upload_id is not None:
if upload_id:
raise ValueError("More than one UploadId for URI %s. Disable multipart upload, or use\n %s multipart %s\nto list the Ids, then pass a unique --upload-id into the put command." % (uri, sys.argv[0], uri))
upload_id = mp_upload_id
except KeyError:
Expand All @@ -62,14 +62,14 @@ def initiate_multipart_upload(self):
Begin a multipart upload
http://docs.amazonwebservices.com/AmazonS3/latest/API/index.html?mpUploadInitiate.html
"""
if self.s3.config.upload_id is not None:
if self.s3.config.upload_id:
self.upload_id = self.s3.config.upload_id
elif self.s3.config.put_continue:
self.upload_id = self.get_unique_upload_id(self.uri)
else:
self.upload_id = None
self.upload_id = ""

if self.upload_id is None:
if not self.upload_id:
request = self.s3.create_request("OBJECT_POST", uri = self.uri,
headers = self.headers_baseline,
uri_params = {'uploads': None})
Expand Down
2 changes: 1 addition & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def _guess_content_type(self, filename):

def stdin_content_type(self):
content_type = self.config.mime_type
if content_type == '':
if not content_type:
content_type = self.config.default_mime_type

content_type += "; charset=" + self.config.encoding.upper()
Expand Down
2 changes: 1 addition & 1 deletion s3cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2875,7 +2875,7 @@ def main():
raise ParameterError("Chunk size %d MB is too large, must be <= %d MB. Please adjust --multipart-chunk-size-mb" % (cfg.multipart_chunk_size_mb, MultiPartUpload.MAX_CHUNK_SIZE_MB))

## If an UploadId was provided, set put_continue True
if options.upload_id is not None:
if options.upload_id:
cfg.upload_id = options.upload_id
cfg.put_continue = True

Expand Down

0 comments on commit d07bcfa

Please sign in to comment.