I have a question about serving/rendering an image saved in the blobstore
I get a 404 error
It seems to find the url?? http://clockinapple.appspot.com/serve/AMIfv97XybVYJy5Jk1e7WCSfCc-IO7zBtlVaC8ef8-Im /etc/
The code is basically the same as the example – any help greatly appreciated
This is my handler code:
class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self, resource):
resource = unicode(str(urllib.unquote(resource)))
blob_info = blobstore.BlobInfo.get(resource)
self.send_blob(blob_info)
class GetBlobstoreUrl(BaseHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload/')
self.response.out.write(upload_url)
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file')
blob_info = upload_files[0]
user_info = blobstore.BlobInfo.all().get().filename
text = user_info
head, sep, tail = text.partition('.')
user_info = head
photo = clockin.UserPhoto(blob_key=blob_info.key(), employee=user_info)
photo.put()
class GetLogs(BaseHandler):
def get(self):
logs = clockin.UserPhoto.all()
params = {'logs': logs}
return self.render_template('logs.html', **params)
This is my model code:
class UserPhoto(db.Model):
employee = db.StringProperty(db.Key)
blob_key = blobstore.BlobReferenceProperty()
create_timestamp = db.DateTimeProperty(auto_now_add=True)
update_timestamp = db.DateTimeProperty(auto_now=True)
My routes:
RedirectRoute('/serve/([^/]+)?', ServeHandler, name='serve_handler', strict_slash=True),
RedirectRoute('/logs/', GetLogs, name='get_logs', strict_slash=True),
RedirectRoute('/get_blobstore_url/', GetBlobstoreUrl, name='get_blobstore_url', strict_slash=True),
How I serve the html: (us is the instance)
<td><img src='/serve/{{us.blob_key.key()}}'></img></td>
I queried the blobstore directly and the images displayed correctly
I hope this can help someone
My handler:
On the HTML side: