Retrieving uploaded Blob info from a regular handler

I would like to use Google's BlobStore for my GAE app. I want the user to upload an image along with other form data. I know I can just use self.request.get event from within a BlobstoreUploadHandler to fetch other form data. However, I have created a subclass of appengine's generic handler (i.e. class Handler(webapp.RequestHandler)) that incorporates other methods I want all of my handlers to have. Is there I way I can still have my upload handler inherit from Handler and still get the blob info?

Normal way to fetch blobs

class UploadHandler(blobstore.BlobstoreUploadHandler):
    def post(self):
        blob_info = self.get_uploads("image")

Way I want to fetch blobs

class Handler(webapp.RequestHandler):
    def get_logged_in_user(self):
         #check cookie and session data
         return username

class UploadHandler(Handler):
    def post(self):
        image_info = # Somehow get blobinfo
        Data = Data(title=self.request.get("name"), image=image_info)

Note: I don't want to make Handler inherit from BlobstoreUploadHandler because I use the Handler class for other handlers as well.

Answers


You could create a mixin class which defines your special methods and use that to create handler. You could then use the same mixin to create the upload handler...

class HandlerMixin(object):
    def get_logged_in_user(self):
        ...

class Handler(webapp2.RequestHandler, HandlerMixin):
    pass

class UploadHandler(blobstore.BlobstoreUploadHandler, HandlerMixin):
    def post(self):
        ...

1Note that the BlobstoreUploadHandler is a subclass of webapp.RequestHandler rather than webapp2.RequestHandler. I think that in most ways, webapp and webapp2 are API compatible, but just know that if you do something funky in HandlerMixin which requires webapp2 instead of just webapp, that method won't work in UploadHandler.


Need Your Help

regex to match postgresql bytea

regex perl postgresql

In PostgreSQL, there is a BLOB datatype called bytea. It's just an array of bytes.

Efficient slicing of matrices using matrix multiplication, with Python, NumPy, SciPy

python numpy scipy aggregate sparse-matrix

I want to reshape a 2d scipy.sparse.csr.csr_matrix(let us call it A) to a 2d numpy.ndarray (let us call this B).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.