Skip to content

Storage document upload policy snippet #3222

@daspecster

Description

@daspecster

Storage snippet for generate_upload_policy seems to be broken. I looked at the docs but I don't see where the breakdown is.

Here's the output when trying to upload with the generated HTML form.

<Error>
<Code>InvalidArgument</Code>
<Message>Invalid argument.</Message>
<Details>Cannot create buckets using a POST.</Details>
</Error>
bucket = client.bucket('my-bucket24356uytrew')
conditions = [
    ['starts-with', '$key', ''],
    {'acl': 'public-read'}]

policy = bucket.generate_upload_policy(conditions)

# Generate an upload form using the form fields.
policy_fields = ''.join(
    '<input type="hidden" name="{key}" value="{value}">'.format(
        key=key, value=value)
    for key, value in policy.items()
)

upload_form = (
    '<form action="http://{bucket_name}.storage.googleapis.com"'
    '   method="post" enctype="multipart/form-data">'
    '<input type="text" name="key" value="">'
    '<input type="hidden" name="bucket" value="{bucket_name}">'
    '<input type="hidden" name="acl" value="public-read">'
    '<input name="file" type="file">'
    '<input type="submit" value="Upload">'
    '{policy_fields}'
    '<form>').format(bucket_name=bucket.name, policy_fields=policy_fields)

print(upload_form)

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions