Repository: googleapis/google-cloud-python

Issue:
Storage document upload policy snippet
Storage [snippet for generate_upload_policy](https://googlecloudplatform.github.io/google-cloud-python/stable/storage-buckets.html#google.cloud.storage.bucket.Bucket.generate_upload_policy) seems to be broken. I looked at [the docs](https://cloud.google.com/storage/docs/xml-api/post-object#policydocument) but I don't see where the breakdown is.

Here's the output when trying to upload with the generated HTML form.

```xml
<Error>
<Code>InvalidArgument</Code>
<Message>Invalid argument.</Message>
<Details>Cannot create buckets using a POST.</Details>
</Error>
```


```python
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)
```


Discussion:
@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.
Re-opening issue until the snippet is restored in source
@jonparrott, ah thanks. Sorry I missed that.

Resolving patch:
diff --git a/docs/storage_snippets.py b/docs/storage_snippets.py
--- a/docs/storage_snippets.py
+++ b/docs/storage_snippets.py
@@ -223,6 +223,39 @@ def list_buckets(client, to_delete):
         to_delete.append(bucket)
 
 
+@snippet
+def policy_document(client, to_delete):
+    # pylint: disable=unused-argument
+    # [START policy_document]
+    bucket = client.bucket('my-bucket')
+    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="my-test-key">'
+        '<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)
+    # [END policy_document]
+
+
 def _line_no(func):
     code = getattr(func, '__code__', None) or getattr(func, 'func_code')
     return code.co_firstlineno
diff --git a/storage/google/cloud/storage/bucket.py b/storage/google/cloud/storage/bucket.py
--- a/storage/google/cloud/storage/bucket.py
+++ b/storage/google/cloud/storage/bucket.py
@@ -859,6 +859,12 @@ def generate_upload_policy(
         `policy documents`_ to allow visitors to a website to upload files to
         Google Cloud Storage without giving them direct write access.
 
+        For example:
+
+        .. literalinclude:: storage_snippets.py
+            :start-after: [START policy_document]
+            :end-before: [END policy_document]
+
         .. _policy documents:
             https://cloud.google.com/storage/docs/xml-api\
             /post-object#policydocument


Test patch: