Choosing Google Cloud Storage object name when uploading a file using Python blobstore API -


i migrating blobstore google cloud storage in google app engine python app. use blobstore api when uploading gcs. ok, according gae python documentation regarding blobstore

the flow works storing blobstore. client requests upload url, blobstore.create_upload_url(...) creates it, client uploads file via multipart post, , server redirects upload handler in gae application.

the problem though got choose gcs bucket (it 1 of parameters of create_upload_url call) don't see how can choose file name. break down folders. inspiration comes

google app engine blobstore google cloud storage migration tool filename broken browsing of gcs "folders" manageable.

i know of 1 way of naming gcs file - forego blobstore api. instead client upload file gae handler, use lib.cloudstorage write file data gcs - exacly quoted migration tool does.

i lose gcs goodies retries on errors during upload.

the question: there way upload file directly gcs, while impacting way resulting gcs object named.

repository : https://github.com/voscausa/appengine-gcs-upload

example code first option.

  • where can name bucket object
  • and use signed url access bucket

docs: https://cloud.google.com/storage/docs/reference-methods?hl=bg#postobject

the upload template:

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>'gcs_upload'</title> </head> <body>     <form action="http://storage.googleapis.com/{{ form_bucket }}"           method="post" enctype="multipart/form-data">         <input type="text" name="key" value="">         <input type="hidden" name="googleaccessid" value="{{ form_access_id }}">         <input type="hidden" name="acl" value="bucket-owner-read">         <input type="hidden" name="success_action_redirect" value="{{ form_succes_redirect }}">         <input type="hidden" name="policy" value="{{ form_policy }}">         <input type="hidden" name="signature" value="{{ form_signature }}">         <input type="file" name="file">         <input type="submit" value="upload">     </form> </body> </html> 

the upload form handler:

class gcsupload(basehandler):      def get(self):          default_bucket = app_identity.get_default_gcs_bucket_name()         google_access_id = app_identity.get_service_account_name()         succes_redirect = 'http://www.example.com/success'         policy_string = """         {"expiration": "2015-06-22t18:11:11z",                   "conditions": [                       ["starts-with", "$key", ""],                       {"acl": "bucket-owner-read"},                       {"success_action_redirect": "%s"},                   ]}""" % succes_redirect          policy = base64.b64encode(policy_string)         _, signature_bytes = app_identity.sign_blob(policy)         signature = base64.b64encode(signature_bytes)          self.render_template('gcs_upload.html', form_bucket=default_bucket, form_succes_redirect=succes_redirect,                              form_access_id=google_access_id, form_signature=signature, form_policy=policy) 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -