-3

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

Sahibzada
  • 143
  • 1
  • 11
  • 1
    Possible duplicate of [Uploading Files in webapp2/GAE](https://stackoverflow.com/questions/27973109/uploading-files-in-webapp2-gae) – phd Jul 14 '17 at 15:49

1 Answers1

0

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
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424