I don't like your implementation, you should cache generated images and
let them be downloaded as static content.


For my site I implemented helper function for template. It accepts
image database object (with original filename) and size as params, then
it checks if specific size was already generated, if not — then it
generates thumbnail of needed size, saves it into static folder, and
then returns url to the image, which is then served from static folder.








As for file streaming, I had a case where I need to forbid access to
some files and so the cannot be put into static folder. To stream file
the i used generator which is supported in webpy. (I use
web.auto_application for url mapping):



class DownloadFile(app.page):

path="/(users|tenders)/(\d+)/files/(\d+)"

def GET(self, obj_type, obj_id, file_id):
obj = db.select(obj_type, vars=locals(), where="id=$obj_id", limit=1)[0]
return self.get(obj, obj_type, obj_id, file_id)

@file_download_access
def get(self, obj, obj_type, obj_id, file_id):
doc = db.select("files", locals(), where="id=$file_id and
obj_type=$obj_type and obj_id=$obj_id", limit=1)[0]
web.header("Content-Disposition", "attachment; filename=%s" %
doc.filename)
web.header("Content-Type", doc.filetype)
web.header('Transfer-Encoding','chunked')
f = open(os.path.join(config.upload_dir, doc.path, doc.filename), 'rb')
while 1:
buf = f.read(1024 * 8)
if not buf:
break
yield buf

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to