diff --git a/docs/storage_snippets.py b/docs/storage_snippets.py index d8ea8f5c30a7..f41629dff5a0 100644 --- a/docs/storage_snippets.py +++ b/docs/storage_snippets.py @@ -94,6 +94,7 @@ def download_to_file(client, to_delete): bucket = client.get_bucket('my-bucket') encryption_key = 'c7f32af42e45e85b9848a6a14dd2a8f6' blob = Blob('secure-data', bucket, encryption_key=encryption_key) + blob.upload_from_string('my secret message.') with open('/tmp/my-secure-file', 'wb') as file_obj: blob.download_to_file(file_obj) # [END download_to_file] @@ -138,7 +139,8 @@ def delete_blob(client, to_delete): from google.cloud.exceptions import NotFound client = storage.Client() bucket = client.get_bucket('my-bucket') - assert isinstance(bucket.list_blobs(), list) + blobs = list(bucket.list_blobs()) + assert len(blobs) > 0 # [] bucket.delete_blob('my-file.txt') try: @@ -221,39 +223,6 @@ 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( - ''.format( - key=key, value=value) - for key, value in policy.items() - ) - - upload_form = ( - '
' - '' - '' - '' - '' - '' - '{policy_fields}' - '').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 index 0863fe48a803..af74baee5044 100644 --- a/storage/google/cloud/storage/bucket.py +++ b/storage/google/cloud/storage/bucket.py @@ -857,12 +857,6 @@ 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