def initiate_multipart_upload(self, key_name, headers=None, reduced_redundancy=False, metadata=None, encrypt_key=False, policy=None, calc_encrypt_md5=True): """ Start a multipart upload operation. Note: After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. Only after you either complete or abort multipart upload, Amazon S3 frees up the parts storage and stops charging you for the parts storage. """ query_args = 'uploads' provider = self.connection.provider headers = headers or {} if policy: headers[provider.acl_header] = policy if reduced_redundancy: storage_class_header = provider.storage_class_header if storage_class_header: headers[storage_class_header] = 'REDUCED_REDUNDANCY' # TODO: what if the provider doesn't support reduced redundancy? if encrypt_key: headers[provider.server_side_encryption_header] = 'AES256' if metadata is None: metadata = {} headers = ks3.utils.merge_meta(headers, metadata, self.connection.provider) if self.connection.local_encrypt: crypts = Crypts(self.connection.key) crypts.calc_md5 = calc_encrypt_md5 crypts.action_info = "init_multi" md5_generator = hashlib.md5() md5_generator.update(crypts.key) headers["x-kss-meta-key"] = base64.b64encode(md5_generator.hexdigest().encode()).decode() headers["x-kss-meta-iv"] = base64.b64encode(crypts.first_iv).decode() response = self.connection.make_request('POST', self.name, key_name, query_args=query_args, headers=headers) else: response = self.connection.make_request('POST', self.name, key_name, query_args=query_args, headers=headers) body = response.read() if response.status == 200: resp = MultiPartUpload(self) if self.connection.local_encrypt: resp.set_crypt_context(crypts) h = handler.XmlHandler(resp, self) if not isinstance(body, bytes): body = body.encode('utf-8') xml.sax.parseString(body, h) return resp else: raise self.connection.provider.storage_response_error( response.status, response.reason, body)
def initiate_multipart_upload(self, key_name, headers=None, reduced_redundancy=False, metadata=None, encrypt_key=False, policy=None, calc_encrypt_md5=True): """ Start a multipart upload operation. Note: After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. Only after you either complete or abort multipart upload, Amazon S3 frees up the parts storage and stops charging you for the parts storage. """ query_args = 'uploads' provider = self.connection.provider headers = headers or {} if policy: headers[provider.acl_header] = policy if reduced_redundancy: storage_class_header = provider.storage_class_header if storage_class_header: headers[storage_class_header] = 'REDUCED_REDUNDANCY' # TODO: what if the provider doesn't support reduced redundancy? if encrypt_key: headers[provider.server_side_encryption_header] = 'AES256' if metadata is None: metadata = {} headers = ks3.utils.merge_meta(headers, metadata, self.connection.provider) if self.connection.local_encrypt: crypts = Crypts(self.connection.key) crypts.calc_md5 = calc_encrypt_md5 crypts.action_info = "init_multi" md5_generator = hashlib.md5() md5_generator.update(crypts.key) headers["x-kss-meta-key"] = base64.b64encode(md5_generator.hexdigest()) headers["x-kss-meta-iv"] = base64.b64encode(crypts.first_iv) response = self.connection.make_request('POST', self.name, key_name, query_args=query_args, headers=headers) else: response = self.connection.make_request('POST', self.name, key_name, query_args=query_args, headers=headers) body = response.read() if response.status == 200: resp = MultiPartUpload(self) if self.connection.local_encrypt: resp.set_crypt_context(crypts) h = handler.XmlHandler(resp, self) if not isinstance(body, bytes): body = body.encode('utf-8') xml.sax.parseString(body, h) return resp else: raise self.connection.provider.storage_response_error( response.status, response.reason, body)
def initiate_multipart_upload(self, key_name, headers=None, reduced_redundancy=False, metadata=None, encrypt_key=False, policy=None): """ Start a multipart upload operation. Note: After you initiate multipart upload and upload one or more parts, you must either complete or abort multipart upload in order to stop getting charged for storage of the uploaded parts. Only after you either complete or abort multipart upload, Amazon S3 frees up the parts storage and stops charging you for the parts storage. """ query_args = 'uploads' provider = self.connection.provider headers = headers or {} if policy: headers[provider.acl_header] = policy if reduced_redundancy: storage_class_header = provider.storage_class_header if storage_class_header: headers[storage_class_header] = 'REDUCED_REDUNDANCY' # TODO: what if the provider doesn't support reduced redundancy? if encrypt_key: headers[provider.server_side_encryption_header] = 'AES256' if metadata is None: metadata = {} headers = ks3.utils.merge_meta(headers, metadata, self.connection.provider) response = self.connection.make_request('POST', self.name, key_name, query_args=query_args, headers=headers) body = response.read() if response.status == 200: resp = MultiPartUpload(self) h = handler.XmlHandler(resp, self) if not isinstance(body, bytes): body = body.encode('utf-8') xml.sax.parseString(body, h) return resp else: raise self.connection.provider.storage_response_error( response.status, response.reason, body)