[web2py] response.stream changes filename of a file, that is being downloaded

2014-07-15 Thread Kuba Kozłowicz

This is my controller's code, that handles requests on following URL:

/app/invoices/download/
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:

.zip
, where  comes from the URL. This  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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] response.stream

2012-10-17 Thread weheh
Is it possible to do a response.stream in the middle of an ajax callback?

I want to give users a button, which if pressed, will tar up all their 
files and initiate a download. Something like this:

TAG.BUTTON(..., _onclick="ajax("%s", [], ':eval');" % URL(c='mycontroller', 
f='mydownload'))

Then later, in mycontroller.py, 

def mydownload():
... create tarfile ...
return response.stream(tarfile, attachment=True)

I tried it, but (perhaps obviously to some) it doesn't work. So, how to get 
the mydownload() action to cause the browser to download the tarfile?

-- 





[web2py] response.stream and web2py_component

2012-09-06 Thread maverick
Hello!
I want to stream a file as an attachment in the response. I have this 
function:
def form_query():
response.flash = str(request.args(0))
response.generic_patterns = ['load']
response.headers['Content-Type'] = 
gluon.contenttype.contenttype('.txt')
response.headers['Content-Disposition'] = 'attachment; 
filename=somefile.txt'
   #more code goes in here to process request.args here. Ultimately, 
the controller is expected to return a dict containing a table and the file 
to be streamed as an attachment. For now just trying to get the file 
streamed.
return response.stream(open('somefile.txt'),chunk_size=1024)

When I call this controller normally (if I put the streaming code inside 
index() for e.g.) it responds by opening up a download popup to save the 
file to disk. But when I have this called as a target function from 
web2py_component in index.html (to fill a div with the response)like this:

web2py_component("{{=URL('reports', 'form_query.load')}}" + "/" + 
jQuery(this).val(), target='div_form_query');

It renders the file inside the DIV 'div_form_query' rather than popup a 
download window.

Any ideas how to render the file as an attachment while using 
web2py_component. I'm using web2py_component as I want to conditionally 
load input forms into that div target (div_form_query) based on a select 
list which has tables as options. The index.html looks something like:

{{left_sidebar_enabled,right_sidebar_enabled=True,False}}
{{extend 'layout.html'}}
{{=message}}
{{=SELECT('Select a report', 
*[OPTION(repts[i].descr, _value=str(repts[i].report)) for i in 
range(len(repts))], _id="rep_type")}}



jQuery(document).ready(function(){
jQuery('#rep_type').change(function(){
web2py_component("{{=URL('reports', 'form_query.load')}}" + "/" + 
jQuery(this).val(), target='div_form_query');
});
 });


{{block left_sidebar}}
{{"""=A(T("Administrative Interface"), 
_href=URL('admin','default','index'), _class='button',
 _style='margin-top: 1em;')"""}}


  {{=A(T("Reports"), _href=URL('netman','reports','index'))}}
  {{=A(T("Billing"), _href=URL('netman','billing','index'))}}
  http://192.168.136.40/zabbix";>{{=T('Monitoring')}}

{{end}}

Thanks,
mave

-- 





[web2py] response.stream on GAE

2011-11-14 Thread Bruno Rocha
Hi,


I have this code working on localhost:

*def download():
> **import os
> **response.stream(os.path.join(request.folder, 'uploads',
> request.args(0)))*


But does not works on GAE

Any hint?


-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] Response.stream problem with zip files

2011-09-15 Thread Deidre
I am using response.stream to download zip files, chunk size 4096. The
files appear to download fine but refuse to unzip. The response.header
content type is set for zip files. Is there a bug?
Peter


[web2py] response.stream problem

2010-01-12 Thread LB22
Hi,

Last night I did an upgrade of web2py from 1.65.x to 1.74.5. Now, this
piece of code:

return response.stream(open(path,'rb'),chuck_size=4096)

...does not work. It was working fine before the upgrade. I've looked
at the changes between versions but I don't see what could have caused
this. Too see what is happening web2py tries to stream the file,
please click here:

http://www.latnblack.com/init/production/preview/53

Maybe someone here knows what is causing this? Thanks in advance for
any help.

LB
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.