def _bucket_response_post(self, request, body, bucket_name):
    response_headers = {}
    if (not request.headers.get('Content-Length')):
        return (411, {}, 'Content-Length required')
    path = self._get_path(request)
    if self.is_delete_keys(request, path, bucket_name):
        self.data['Action'] = 'DeleteObject'
        self._authenticate_and_authorize_s3_action()
        return self._bucket_response_delete_keys(request, body, bucket_name)
    self.data['Action'] = 'PutObject'
    self._authenticate_and_authorize_s3_action()
    if hasattr(request, 'form'):
        form = request.form
    else:
        body = body.decode()
        form = dict(parse_qsl(body))
    key = form['key']
    if ('file' in form):
        f = form['file']
    else:
        fobj = request.files['file']
        f = fobj.stream.read()
        key = key.replace('${filename}', os.path.basename(fobj.filename))
    if ('success_action_redirect' in form):
        redirect = form['success_action_redirect']
        parts = urlparse(redirect)
        queryargs = parse_qs(parts.query)
        queryargs['key'] = key
        queryargs['bucket'] = bucket_name
        redirect_queryargs = urlencode(queryargs, doseq=True)
        newparts = (parts.scheme, parts.netloc, parts.path, parts.params, redirect_queryargs, parts.fragment)
        fixed_redirect = urlunparse(newparts)
        response_headers['Location'] = fixed_redirect
    if ('success_action_status' in form):
        status_code = form['success_action_status']
    elif ('success_action_redirect' in form):
        status_code = 303
    else:
        status_code = 204
    new_key = self.backend.put_object(bucket_name, key, f)
    if form.get('acl'):
        acl = get_canned_acl(form.get('acl'))
        new_key.set_acl(acl)
    metadata = metadata_from_headers(form)
    new_key.set_metadata(metadata)
    return (status_code, response_headers, '')
def _bucket_response_post(self, request, body, bucket_name):
    response_headers = {}
    if (not request.headers.get('Content-Length')):
        return (411, {}, 'Content-Length required')
    path = self._get_path(request)
    if self.is_delete_keys(request, path, bucket_name):
        self.data['Action'] = 'DeleteObject'
        self._authenticate_and_authorize_s3_action()
        return self._bucket_response_delete_keys(request, body, bucket_name)
    self.data['Action'] = 'PutObject'
    self._authenticate_and_authorize_s3_action()
    if hasattr(request, 'form'):
        form = request.form
    else:
        body = body.decode()
        form = dict(parse_qsl(body))
    key = form['key']
    if ('file' in form):
        f = form['file']
    else:
        fobj = request.files['file']
        f = fobj.stream.read()
        key = key.replace('${filename}', os.path.basename(fobj.filename))
    if ('success_action_redirect' in form):
        redirect = form['success_action_redirect']
        parts = urlparse(redirect)
        queryargs = parse_qs(parts.query)
        queryargs['key'] = key
        queryargs['bucket'] = bucket_name
        redirect_queryargs = urlencode(queryargs, doseq=True)
        newparts = (parts.scheme, parts.netloc, parts.path, parts.params, redirect_queryargs, parts.fragment)
        fixed_redirect = urlunparse(newparts)
        response_headers['Location'] = fixed_redirect
    if ('success_action_status' in form):
        status_code = form['success_action_status']
    elif ('success_action_redirect' in form):
        status_code = 303
    else:
        status_code = 204
    new_key = self.backend.put_object(bucket_name, key, f)
    if form.get('acl'):
        acl = get_canned_acl(form.get('acl'))
        new_key.set_acl(acl)
    metadata = metadata_from_headers(form)
    new_key.set_metadata(metadata)
    return (status_code, response_headers, )