

def set_contents_from_file(self, fp, headers=None, replace=True, cb=None, num_cb=10, policy=None, md5=None, res_upload_handler=None, size=None):
    '\n        Store an object in GS using the name of the Key object as the\n        key in GS and the contents of the file pointed to by \'fp\' as the\n        contents.\n\n        :type fp: file\n        :param fp: the file whose contents are to be uploaded\n\n        :type headers: dict\n        :param headers: additional HTTP headers to be sent with the PUT request.\n\n        :type replace: bool\n        :param replace: If this parameter is False, the method will first check\n            to see if an object exists in the bucket with the same key. If it\n            does, it won\'t overwrite it. The default value is True which will\n            overwrite the object.\n\n        :type cb: function\n        :param cb: a callback function that will be called to report\n            progress on the upload. The callback should accept two integer\n            parameters, the first representing the number of bytes that have\n            been successfully transmitted to GS and the second representing the\n            total number of bytes that need to be transmitted.\n\n        :type num_cb: int\n        :param num_cb: (optional) If a callback is specified with the cb\n            parameter, this parameter determines the granularity of the callback\n            by defining the maximum number of times the callback will be called\n            during the file transfer.\n\n        :type policy: :class:`boto.gs.acl.CannedACLStrings`\n        :param policy: A canned ACL policy that will be applied to the new key\n            in GS.\n\n        :type md5: A tuple containing the hexdigest version of the MD5 checksum\n            of the file as the first element and the Base64-encoded version of\n            the plain checksum as the second element. This is the same format\n            returned by the compute_md5 method.\n        :param md5: If you need to compute the MD5 for any reason prior to\n            upload, it\'s silly to have to do it twice so this param, if present,\n            will be used as the MD5 values of the file. Otherwise, the checksum\n            will be computed.\n\n        :type res_upload_handler: ResumableUploadHandler\n        :param res_upload_handler: If provided, this handler will perform the\n            upload.\n\n        :type size: int\n        :param size: (optional) The Maximum number of bytes to read from\n            the file pointer (fp). This is useful when uploading\n            a file in multiple parts where you are splitting the\n            file up into different ranges to be uploaded. If not\n            specified, the default behaviour is to read all bytes\n            from the file pointer. Less bytes may be available.\n            Notes:\n\n                1. The "size" parameter currently cannot be used when\n                   a resumable upload handler is given but is still\n                   useful for uploading part of a file as implemented\n                   by the parent class.\n                2. At present Google Cloud Storage does not support\n                   multipart uploads.\n\n        TODO: At some point we should refactor the Bucket and Key classes,\n        to move functionality common to all providers into a parent class,\n        and provider-specific functionality into subclasses (rather than\n        just overriding/sharing code the way it currently works).\n        '
    provider = self.bucket.connection.provider
    if (res_upload_handler and size):
        raise BotoClientError('"size" param not supported for resumable uploads.')
    headers = (headers or {
        
    })
    if policy:
        headers[provider.acl_header] = policy
    if hasattr(fp, 'name'):
        self.path = fp.name
    if (self.bucket != None):
        if (not md5):
            md5 = self.compute_md5(fp, size)
            size = self.size
        elif size:
            self.size = size
        else:
            spos = fp.tell()
            fp.seek(0, os.SEEK_END)
            self.size = (fp.tell() - spos)
            fp.seek(spos)
            size = self.size
        self.md5 = md5[0]
        self.base64md5 = md5[1]
        if (self.name == None):
            self.name = self.md5
        if (not replace):
            if self.bucket.lookup(self.name):
                return
        if res_upload_handler:
            res_upload_handler.send_file(self, fp, headers, cb, num_cb)
        else:
            self.send_file(fp, headers, cb, num_cb, size=size)

dataset/ETHPy150Open yyuu/botornado/boto/gs/key.py Key.set_contents_from_file/original