Logo Search packages:      
Sourcecode: s3ql version File versions  Download package

def s3ql::backends::boto::s3::connection::S3Connection::build_post_form_args (   self,
  bucket_name,
  key,
  expires_in = 6000,
  acl = None,
  success_action_redirect = None,
  max_content_length = None,
  http_method = "http",
  fields = None,
  conditions = None 
)
Taken from the AWS book Python examples and modified for use with boto
This only returns the arguments required for the post form, not the actual form
This does not return the file input field which also needs to be added

:param bucket_name: Bucket to submit to
:type bucket_name: string 

:param key:  Key name, optionally add ${filename} to the end to attach the submitted filename
:type key: string

:param expires_in: Time (in seconds) before this expires, defaults to 6000
:type expires_in: integer

:param acl: ACL rule to use, if any
:type acl: :class:`boto.s3.acl.ACL`

:param success_action_redirect: URL to redirect to on success
:type success_action_redirect: string 

:param max_content_length: Maximum size for this file
:type max_content_length: integer 

:type http_method: string
:param http_method:  HTTP Method to use, "http" or "https"


:rtype: dict
:return: A dictionary containing field names/values as well as a url to POST to

    .. code-block:: python
    
{
    "action": action_url_to_post_to, 
    "fields": [ 
        {
            "name": field_name, 
            "value":  field_value
        }, 
        {
            "name": field_name2, 
            "value": field_value2
        } 
    ] 
}
    

Definition at line 136 of file connection.py.

                                                                           :
        """
        Taken from the AWS book Python examples and modified for use with boto
        This only returns the arguments required for the post form, not the actual form
        This does not return the file input field which also needs to be added
        
        :param bucket_name: Bucket to submit to
        :type bucket_name: string 
        
        :param key:  Key name, optionally add ${filename} to the end to attach the submitted filename
        :type key: string
        
        :param expires_in: Time (in seconds) before this expires, defaults to 6000
        :type expires_in: integer
        
        :param acl: ACL rule to use, if any
        :type acl: :class:`boto.s3.acl.ACL`
        
        :param success_action_redirect: URL to redirect to on success
        :type success_action_redirect: string 
        
        :param max_content_length: Maximum size for this file
        :type max_content_length: integer 
        
        :type http_method: string
        :param http_method:  HTTP Method to use, "http" or "https"
        
        
        :rtype: dict
        :return: A dictionary containing field names/values as well as a url to POST to
        
            .. code-block:: python
            
                {
                    "action": action_url_to_post_to, 
                    "fields": [ 
                        {
                            "name": field_name, 
                            "value":  field_value
                        }, 
                        {
                            "name": field_name2, 
                            "value": field_value2
                        } 
                    ] 
                }
            
        """
        if fields == None:
            fields = []
        if conditions == None:
            conditions = []
        expiration = time.gmtime(int(time.time() + expires_in))

        # Generate policy document
        conditions.append('{"bucket": "%s"}' % bucket_name)
        if key.endswith("${filename}"):
            conditions.append('["starts-with", "$key", "%s"]' % key[:-len("${filename}")])
        else:
            conditions.append('{"key": "%s"}' % key)
        if acl:
            conditions.append('{"acl": "%s"}' % acl)
            fields.append({ "name": "acl", "value": acl})
        if success_action_redirect:
            conditions.append('{"success_action_redirect": "%s"}' % success_action_redirect)
            fields.append({ "name": "success_action_redirect", "value": success_action_redirect})
        if max_content_length:
            conditions.append('["content-length-range", 0, %i]' % max_content_length)
            fields.append({"name":'content-length-range', "value": "0,%i" % max_content_length})

        policy = self.build_post_policy(expiration, conditions)

        # Add the base64-encoded policy document as the 'policy' field
        policy_b64 = base64.b64encode(policy)
        fields.append({"name": "policy", "value": policy_b64})

        # Add the AWS access key as the 'AWSAccessKeyId' field
        fields.append({"name": "AWSAccessKeyId", "value": self.aws_access_key_id})

        # Add signature for encoded policy document as the 'AWSAccessKeyId' field
        hmac_copy = self.hmac.copy()
        hmac_copy.update(policy_b64)
        signature = base64.encodestring(hmac_copy.digest()).strip()
        fields.append({"name": "signature", "value": signature})
        fields.append({"name": "key", "value": key})

        # HTTPS protocol will be used if the secure HTTP option is enabled.
        url = '%s://%s.s3.amazonaws.com/' % (http_method, bucket_name)

        return {"action": url, "fields": fields}



Generated by  Doxygen 1.6.0   Back to index