Пример #1
0
 def put(self, key, data=None, acl=None, metadata={}, mimetype=None,
         transformer=None, headers={}):
     if isinstance(data, unicode):
         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:
         headers["Content-Length"] = str(len(data))
     if "Content-MD5" not in headers:
         headers["Content-MD5"] = aws_md5(data)
     s3req = self.request(method="PUT", key=key, data=data, headers=headers)
     self.send(s3req).close()
Пример #2
0
    def copy(self, source, key, acl=None, metadata=None,
             mimetype=None, headers={}):
        """Copy S3 file *source* on format '<bucket>/<key>' to *key*.

        If metadata is not None, replaces the metadata with given metadata,
        otherwise copies the previous metadata.

        Note that *acl* is not copied, but set to *private* by S3 if not given.
        """
        headers = headers.copy()
        headers.update({"Content-Type": mimetype or guess_mimetype(key)})
        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"
        self.send(self.request(method="PUT", key=key, headers=headers)).close()
Пример #3
0
    def copy(self,
             source,
             key,
             acl=None,
             metadata=None,
             mimetype=None,
             headers={}):
        """Copy S3 file *source* on format '<bucket>/<key>' to *key*.

        If metadata is not None, replaces the metadata with given metadata,
        otherwise copies the previous metadata.

        Note that *acl* is not copied, but set to *private* by S3 if not given.
        """
        headers = headers.copy()
        headers.update({"Content-Type": mimetype or guess_mimetype(key)})
        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"
        self.send(self.request(method="PUT", key=key, headers=headers)).close()
Пример #4
0
 def put(self,
         key,
         data=None,
         acl=None,
         metadata={},
         mimetype=None,
         transformer=None,
         headers={}):
     if isinstance(data, unicode):
         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:
         headers["Content-Length"] = str(len(data))
     if "Content-MD5" not in headers:
         headers["Content-MD5"] = aws_md5(data)
     s3req = self.request(method="PUT", key=key, data=data, headers=headers)
     self.send(s3req).close()