def update_meta(self, key, metadata={}, acl=None, mimetype=None, headers={}): ''' 更新文件meta信息 删除meta功能暂时不可用 ''' headers = headers.copy() if mimetype: headers["Content-Type"] = str(mimetype) elif "Content-Type" not in headers: headers["Content-Type"] = guess_mimetype(key) headers.update(metadata_headers(metadata)) # headers.update(metadata_remove_headers(remove_metadata)) if acl: headers["X-AMZ-ACL"] = acl if "Content-Length" not in headers: headers["Content-Length"] = 0 scsreq = self.request(method="PUT", key=key, headers=headers, subresource='meta') return self.send(scsreq).close()
def put_relax(self,key,sina_sha1, s_sina_length, acl=None, metadata={}, mimetype=None,headers={}): ''' 上传接口Relax REST型PUT上传,但不上传具体的文件内容。而是通过SHA-1值对系统内文件进行复制。 ''' # if isinstance(sina_sha1, six.text_type): # sina_sha1 = sina_sha1.encode(self.default_encoding) headers = headers.copy() if mimetype: headers["Content-Type"] = str(mimetype) elif "Content-Type" not in headers: headers["Content-Type"] = guess_mimetype(key) if sina_sha1 == None: raise ValueError("sina_sha1 must not None!!") if "s-sina-sha1" not in headers: headers["s-sina-sha1"] = sina_sha1 if s_sina_length == 0: raise ValueError("s_sina_length must bigger than 0!!") if "s-sina-length" not in headers: headers["s-sina-length"] = s_sina_length headers.update(metadata_headers(metadata)) if acl: headers["X-AMZ-ACL"] = acl if "Content-Length" not in headers: headers["Content-Length"] = 0 scsreq = self.request(method="PUT", key=key, headers=headers,subresource='relax') return self.send(scsreq).close()
def initiate_multipart_upload(self, key_name, acl=None, metadata={}, mimetype=None, headers={}): ''' 初始化分片上传 return type : dict { u'UploadId': u'535dd723761d4f14a7210945cd7dea11', u'Key': u'test-python.zip', u'Bucket': u'create-a-bucket' } ''' headers = headers.copy() if headers else {} if mimetype: headers["Content-Type"] = str(mimetype) elif "Content-Type" not in headers: headers["Content-Type"] = guess_mimetype(key_name) headers.update(metadata_headers(metadata)) if acl: headers["X-AMZ-ACL"] = acl headers["Content-Length"] = "0" scsreq = self.request(method="POST", key=key_name, headers=headers, subresource='multipart') scsResponse = self.send(scsreq) initMultipartUploadResult = json.loads(scsResponse.read()) scsResponse.close() from sinastorage.multipart import MultipartUpload multipart = MultipartUpload(self) multipart.upload_id = initMultipartUploadResult["UploadId"] multipart.bucket_name = initMultipartUploadResult["Bucket"] multipart.key_name = initMultipartUploadResult["Key"] multipart.init_multipart_response = scsResponse return multipart
def put(self, key, data=None, acl=None, metadata={}, mimetype=None, transformer=None, headers={},args=None,subresource=None): if isinstance(data, six.text_type): data = data.encode(self.default_encoding) headers = headers.copy() if mimetype: headers["Content-Type"] = str(mimetype) elif "Content-Type" not in headers: headers["Content-Type"] = guess_mimetype(key) headers.update(metadata_headers(metadata)) if acl: headers["X-AMZ-ACL"] = acl if transformer: data = transformer(headers, data) if "Content-Length" not in headers: # if isinstance(data, file) isinstance(data, FileChunkIO): if hasattr(data,'fileno'): headers["Content-Length"] = str(getSize(data.name)) elif hasattr(data,'__len__'): headers["Content-Length"] = str(len(data)) else: raise ValueError("Content-Length must be defined!!") # if "s-sina-sha1" not in headers: # headers["s-sina-sha1"] = aws_md5(data) scsreq = self.request(method="PUT", key=key, data=data, headers=headers, args=args, subresource=subresource) scsResponse = self.send(scsreq) return scsResponse
def copy(self, source, key, acl=None, metadata=None, mimetype=None, headers={}): """ 注意: source 必须从bucket开始,如:'/cloud0/aaa.txt' """ headers = headers.copy() headers.update({"Content-Type": mimetype or guess_mimetype(key)}) if "Content-Length" not in headers: headers["Content-Length"] = 0 headers["X-AMZ-Copy-Source"] = source if acl: headers["X-AMZ-ACL"] = acl if metadata is not None: headers["X-AMZ-Metadata-Directive"] = "REPLACE" headers.update(metadata_headers(metadata)) else: headers["X-AMZ-Metadata-Directive"] = "COPY" return self.send(self.request(method="PUT", key=key, headers=headers)).close()