I am using python webapp2 (Python framework) and google app engine for my project, i want to upload files to my project directory just like move_upload_files in php
Thanks
I am using python webapp2 (Python framework) and google app engine for my project, i want to upload files to my project directory just like move_upload_files in php
Thanks
You can upload files to the blobstore using webapp2. You first must create the upload url when dispatching to your upload form:
self.render('upload-ui.html', {
...
'form_url': blobstore.create_upload_url('/upload_form'),
})
Then in your upload form you use the form_url
<form method="post" action="{{ form_url }}" name="formular" class="ui form" accept-charset="UTF-8"
enctype="multipart/form-data">
The uploaded files are available from self.get_uploads
in the post method of your code:
for upload in self.get_uploads():
try:
content_type = blobstore.blobstore.BlobInfo(upload.key()).content_type
if 'video' in content_type:
vid = Video(reference=user)
vid.content = upload.key()
vid.title = blobstore.blobstore.BlobInfo(upload.key()).filename
vid.size = blobstore.blobstore.BlobInfo(upload.key()).size
vid.put()
except Exception, e:
logging.error('There was an exception:%s' % str(e.message))
pass