Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage document upload policy snippet #3222

Closed
daspecster opened this issue Mar 28, 2017 · 3 comments
Closed

Storage document upload policy snippet #3222

daspecster opened this issue Mar 28, 2017 · 3 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@daspecster
Copy link
Contributor

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)
@daspecster daspecster added the api: storage Issues related to the Cloud Storage API. label Mar 28, 2017
@tseaver tseaver changed the title Storage document poli Storage document upload policy snippet Mar 28, 2017
@theacodes
Copy link
Contributor

@daspecster this works fine, however, two things:

  1. The closing form tag is <form> instead of </form>. My bad.
  2. You'll get the 'Cannot create buckets using a POST.' if you fail to put a value into the key input field. Granted, the sample outputs a form that doesn't have a label on that field so it's easy to miss.

@dhermes
Copy link
Contributor

dhermes commented Mar 28, 2017

Re-opening issue until the snippet is restored in source

@dhermes dhermes reopened this Mar 28, 2017
@daspecster
Copy link
Contributor Author

@jonparrott, ah thanks. Sorry I missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

3 participants