It works like a charm. I used the stream function and that works too.
#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'))

thanks Niphlod you are awesome.

On Sunday, April 14, 2013 3:21:18 PM UTC+2, Niphlod wrote:
>
> ok. So, basically the problem is that response.stream is a "special" kind 
> of function.
> It raises HTTP(200, content_of_the_file) instead of returning it, and 
> raising an HTTP(200) is a smart way to do it.
> Unfortunately, this means that
> def download():
>       return response.stream(....)
>
> basically doesn't return from download, it raises an exception inside 
> response.stream and the execution is cutted of right in the response.stream 
> function.
>
> A decorator "outside" download() doesn't work, because it doesn't have the 
> chance to execute that function completely.
> Now, on the bright side, the download() function should be the only one 
> behaving in this way, so the cache.client implementation shouldn't change.
>
> I'll see if we can use a "public" function just to adjust headers 
> beforehand without requiring for the actual function.
> For the time being, this works ok.
>
>  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)
>
> basically because cache.client is coded to be a decorator, you have to 
> pass it a function.
> In this case, a dummy "lambda:0" is passed. To fire the actual 
> "calculations" of the cache decorator, you have to call it (and that's why 
> there's an empty () at the end). The headers are then manipulated in the 
> current response, so response.download pick it up where headers are already 
> set, and when it returns the image, the headers are shipped with the 
> response.
>
> If you have any doubts, please ask.
>
>

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to