Emrecan Agah
Emrecan Agah

Reputation: 31

Google App Engine upload image Blobstore

I want to make users that upload image and make a demo for this uplaod, and read GAE Blobstore API.

My problem is when submitting the image file, I get error AttributeError: 'UploadHandlerDemo' object has no attribute 'get' but Blob class is already created in datastore. How can I handle this problem ?

Here my code snippet:

class FileUploadDemo(webapp2.RequestHandler):
    def get(self):
        from google.appengine.ext import blobstore
        upload_url = blobstore.create_upload_url('/admin/upload')
        logging.info(upload_url)
        blob = blobstore.BlobInfo.all().get()
        logging.info(blob.filename)
        content = {"upload_url":upload_url}
        HelperGlobal.render_template(self, 'blobstoreDemo.html', content)

Here my UploadHandler:

from google.appengine.ext.webapp import blobstore_handlers
class UploadHandlerDemo(blobstore_handlers.BlobstoreUploadHandler):
    def post(self):
        upload_files = self.get.uploads('file')
        blob_info = upload_files[0]   
        logging.info(blob_info) 
        self.redirect('/admin/serve/%s' % blob_info.key())

In datastore path I had BlobInfo and BlobUplaodSessions and they are seeming fine.

In html part, I convert GAE Blobstore example to single HTML which rendered with upload_url data by help of JINJA.

Here My HTML code for simple demo:

<html>
<body>
<form action="{{upload_url}}" method="POST" enctype="multipart/form-data">
Upload File: <input type="file" name="file" id="UniqueFile">
             <br> 
             <input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

When I press submit button, It creates BlobInfo entity with corresponding image, but server gets Error with code 500, and says :

AttributeError: 'UploadHandlerDemo' object has no attribute 'get'

I had many tries and looks stackoverflow but could not get a solution.

Upvotes: 2

Views: 866

Answers (3)

shahzeb akram
shahzeb akram

Reputation: 926

you have to replace this

upload_files = self.get.uploads('file')

to

upload_files = get_uploads('file')

Upvotes: 1

joe.ritchey
joe.ritchey

Reputation: 31

I think: upload_files = self.get.uploads('file')

should be : upload_files = self.get_uploads('file')

Upvotes: 1

Ying Li
Ying Li

Reputation: 2519

AttributeError: 'UploadHandlerDemo' object has no attribute 'get'

It's probably referring to this line:

upload_files = self.get.uploads('file')

Show us the rest of your code from UploadHandlerDemo please.

Did you have a "get" attribute setup? I am not really sure what you are trying to do with self.get.uploads('file'). Are you calling the get object in self (UploadHandlerDemo)? The get object needs to own the uploads(file) method.

Upvotes: 0

Related Questions