def fast_download():
# very basic security (only allow fast_download on your_table.upload_field):
if not request.args(0).startswith("db.your_table.your_field"):
return download()
# remove/add headers that prevent/favors client-side caching
#7days
response.headers['Cache-Control'] = "max-age=604800"
del response.headers['Pragma']
del response.headers['Expires']
filename = os.path.join(request.folder,'uploads',request.args(0))
# send last modified date/time so client browser can enable client-side caching
response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(os.path.getmtime(filename)))
return response.stream(open(filename,'rb'))--
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
#7days
@cache.client(time_expire=604800, quick='SVL')
def fast_download():
session.forget(response)
# very basic security (only allow fast_download on your_table.upload_field):
if not request.args(0).startswith("db.Images"):
return download()
# remove/add headers that prevent/favors client-side caching
#del response.headers['Cache-Control']
#del response.headers['Pragma']
#del response.headers['Expires']
filename = os.path.join(request.folder,'uploads',request.args(0))
#response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(os.path.getmtime(filename)))
return response.stream(open(filename,'rb'))
def download():
cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
return response.download(request, db)#7days
def fast_download():
session.forget(response)
cache.client(time_expire=604800)(lambda: 0)()
# very basic security (only allow fast_download on your_table.upload_field):
if not request.args(0).startswith("db.Images"):
return download()
filename = os.path.join(request.folder,'uploads',request.args(0))
return response.stream(open(filename,'rb'))
def fast_download():
import time, os
import contenttype as c
cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
file_id = request.args(-1)
myfile = db.file(db.file.file==file_id)
filename, file = db.file.file.retrieve(myfile.file)
response.headers["Content-Type"] = c.contenttype(file_id)
response.headers["Content-Disposition"] = "attachment; filename=%s" % filename
stream = response.stream(file, chunk_size=64*1024, request=request)
raise HTTP(200, stream, **response.headers)cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
AttributeError: 'Cache' object has no attribute 'client'
Am I missing something?
Cheers
-James
def fast_download():
import time, os
import contenttype as
c
cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
file_id = request.args(-1)
myfile = db.file(db.file.file==file_id)
filename, file = db.file.file.retrieve(myfile.file)
response.headers["Content-Type"] = c.contenttype(file_id)
response.headers["Content-Disposition"] = "attachment; filename=%s" % filename
stream = response.stream(file, chunk_size=64*1024, request=request)
raise HTTP(200, stream, **response.headers)
I tried using the above code, but results in the follow error message:
cache.client(time_expire=604800, quick='SVL')(lambda: 0)()
AttributeError: 'Cache' object has no attribute 'client'
Am I missing something?
Cheers
-James
On Monday, April 15, 2013 1:21:18 AM UTC+12, Niphlod wrote:
@cache.action(time_expire=1200, cache_model=cache.memcache, quick='SVL')
def fast_download():
import time, os
import contenttype as c
# very basic security:
if not request.args(0).startswith("file.file"):
return download()
file_id = request.args(-1)
myfile = db.file(db.file.file==file_id)
filename, file = db.file.file.retrieve(myfile.file)
response.headers["Content-Type"] = c.contenttype(file_id)
response.headers["Content-Disposition"] = "attachment; filename=%s" % filename
#response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(myfile.last_modified))
stream = response.stream(file, chunk_size=64*1024, request=request)
raise HTTP(200, stream, **response.headers)PicklingError: Can't pickle <type 'generator'>: attribute lookup __builtin__.generator failed
Is there a way to response.render the download?
I want to be able to cache my images. Client side, server side it doesn't matter.
What is the best method to go about this?