probably you're not running a recent web2py release.

On Saturday, January 25, 2014 9:37:12 PM UTC+1, James Burke wrote:
>
> 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:
>>
>> 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.
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to