def _check_upload_record(self, record): if not ((record['bucketName'] == self.bucketName) and (record['objectKey'] == self.objectKey) and (record['uploadFile'] == self.fileName)): self.obsClient.log_client.log( INFO, 'the bucketName or objectKey or uploadFile was changed. clear the record' ) return False if record['uploadId'] is None: self.obsClient.log_client.log( INFO, '{0} (uploadId) not exist, clear the record.'.format( record['upload_id'])) return False if record['fileStatus'][0] != self.size or record['fileStatus'][ 1] != self.lastModified: self.obsClient.log_client.log( INFO, '{0} was changed, clear the record.'.format(self.fileName)) return False if self.checkSum and len(record['fileStatus']) >= 3: checkSum = util.base64_encode( util.md5_file_encode_by_size_offset(file_path=self.fileName, size=self.size, offset=0)) if record['fileStatus'][2] and record['fileStatus'][2] != checkSum: self.obsClient.log_client.log( INFO, '{0} content was changed, clear the record.'.format( self.fileName)) return False return True
def _prepare(self): fileStatus = [self.size, self.lastModified] if self.checkSum: fileStatus.append(util.base64_encode(util.md5_file_encode_by_size_offset(self.fileName, self.size, 0))) if self.headers is None: self.headers = UploadFileHeader() resp = self.obsClient.initiateMultipartUpload(self.bucketName, self.objectKey, metadata=self.metadata, acl=self.headers.acl, storageClass=self.headers.storageClass, websiteRedirectLocation=self.headers.websiteRedirectLocation, contentType=self.headers.contentType, sseHeader=self.headers.sseHeader, expires=self.headers.expires, extensionGrants=self.headers.extensionGrants, extensionHeaders=self.extensionHeaders) if resp.status > 300: raise Exception('initiateMultipartUpload failed. ErrorCode:{0}. ErrorMessage:{1}'.format(resp.errorCode, resp.errorMessage)) uploadId = resp.body.uploadId self._record = {'bucketName': self.bucketName, 'objectKey': self.objectKey, 'uploadId': uploadId, 'uploadFile': self.fileName, 'fileStatus': fileStatus, 'uploadParts': self._slice_file(), 'partEtags': []} self.obsClient.log_client.log(INFO, 'prepare new upload task success. uploadId = {0}'.format(uploadId)) if self.enableCheckPoint: self._write_record(self._record)
def _prepare(self): fileStatus = [self.size, self.lastModified] if self.checkSum: fileStatus.append(util.base64_encode(util.md5_file_encode_by_size_offset(self.fileName, self.size, 0))) resp = self.get_init_upload_result() if resp.status > 300: raise Exception('initiateMultipartUpload failed. ErrorCode:{0}. ErrorMessage:{1}'.format(resp.errorCode, resp.errorMessage)) uploadId = resp.body.uploadId self._record["uploadParts"] = self._slice_file() self._record["uploadId"] = uploadId self._record["fileStatus"] = fileStatus self.obsClient.log_client.log(INFO, 'prepare new upload task success. uploadId = {0}'.format(uploadId)) if self.enableCheckPoint: self._write_record(self._record)
allowedHeader=['Authorization1'], maxAgeSecond=100, exposeHeader=['x-obs-test1']) cors2 = CorsRule(id='rule2', allowedMethod=['PUT', 'HEAD', 'GET'], allowedOrigin=['http://www.c.com', 'http://www.d.com'], allowedHeader=['Authorization2'], maxAgeSecond=200, exposeHeader=['x-obs-test2']) corsList = [cors1, cors2] content = Convertor('').trans_cors_rules(corsList) headers = { 'Content-Type': 'application/xml', 'Content-Length': str(len(content)), 'Content-MD5': base64_encode(md5_encode(content)) } res = obsClient.createSignedUrl(method, bucketName, specialParam='cors', headers=headers) doAction('Setting bucket cors', method, res['signedUrl'], res['actualSignedRequestHeaders'], content) method = 'GET' res = obsClient.createSignedUrl(method, bucketName, specialParam='cors') doAction('Getting bucket cors', method, res['signedUrl'], res['actualSignedRequestHeaders']) method = 'DELETE' res = obsClient.createSignedUrl(method, bucketName, specialParam='cors')