@@ -223,6 +223,39 @@ def list_buckets(client, to_delete):
223223 to_delete .append (bucket )
224224
225225
226+ @snippet
227+ def policy_document (client , to_delete ):
228+ # pylint: disable=unused-argument
229+ # [START policy_document]
230+ bucket = client .bucket ('my-bucket' )
231+ conditions = [
232+ ['starts-with' , '$key' , '' ],
233+ {'acl' : 'public-read' }]
234+
235+ policy = bucket .generate_upload_policy (conditions )
236+
237+ # Generate an upload form using the form fields.
238+ policy_fields = '' .join (
239+ '<input type="hidden" name="{key}" value="{value}">' .format (
240+ key = key , value = value )
241+ for key , value in policy .items ()
242+ )
243+
244+ upload_form = (
245+ '<form action="http://{bucket_name}.storage.googleapis.com"'
246+ ' method="post" enctype="multipart/form-data">'
247+ '<input type="text" name="key" value="my-test-key">'
248+ '<input type="hidden" name="bucket" value="{bucket_name}">'
249+ '<input type="hidden" name="acl" value="public-read">'
250+ '<input name="file" type="file">'
251+ '<input type="submit" value="Upload">'
252+ '{policy_fields}'
253+ '</form>' ).format (bucket_name = bucket .name , policy_fields = policy_fields )
254+
255+ print (upload_form )
256+ # [END policy_document]
257+
258+
226259def _line_no (func ):
227260 code = getattr (func , '__code__' , None ) or getattr (func , 'func_code' )
228261 return code .co_firstlineno
0 commit comments