you're missing a parameter

response.stream(......., attachment=True)

and, BTW, instead of doing your own parsing, request.args(0) holds 10 
automatically.


On Tuesday, July 15, 2014 10:24:20 AM UTC+2, Kuba Kozłowicz wrote:
>
>
> This is my controller's code, that handles requests on following URL:
>
> /app/invoices/download/<id>
> for instance:
>
>
> /app/invoices/download/10
> to download bundle of invoices, which ID is equal to 10
>
>
> def download():
>     url_parts = request.url.split('/')
>     bundle_id = url_parts[-1]
>     try:
>         bundle_id = int(bundle_id)
>     except ValueError:
>         raise HTTP(404)
>     dir_with_id = os.path.join(BUNDLES_DIR, str(bundle_id))
>
>     dir_content = [f for f in os.listdir(dir_with_id)
>                    if f.endswith('.zip')
>                    and os.path.isfile(os.path.join(dir_with_id, f))]
>     if len(dir_content) != 1:
>         raise HTTP(404)
>     bundle_file = dir_content[0]
>     bundle_file_path = os.path.join(dir_with_id, bundle_file)
>     print bundle_file
>
>     return response.stream(bundle_file_path, chunk_size=10**6, filename=
> bundle_file,)
>
>
> print bundle_file 
> prints filename with file extension, for instance:
>
> bundle_xyz.zip
> , but I end up downloading a file called:
>
> <id>.zip
> , where <id> comes from the URL. This <id> is also the name of the 
> directory that *bundle_xyz.zip* file is located in, for instance:
>
> /bundles/10/bundle_xyz.zip
>
> , after requesting /app/invoices/download/10 I end up downloading *10.zip* 
> instead of *bundle_xyz.zip*.
>
> My question is how to prevent web2py's response.stream method from 
> changing the filename?
>
>
>
>
>
>

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

Reply via email to