Hi Niphlod, (& Paolo read this!) halt. downloading is something the browser can decide. opening the saved > file is something your operating system does. > The browser can only send the response which gives the user a choice > between saving and opening directly the file. > If the user chooses "open" instead of "save" ... nothing can prevent that. >
At this point the user has only clicked on the request (above code) in the browser and has not responded to the os open/save dialogue which subsequently opens. i.e. the file has not yet been saved by the user (though a version has been written 'earlier' to static/temp on the local machine for use 'later' when the user clicks/calls response.stream() this is because I am developing on localhost. In production obviously the static/temp directory will be on a remote server. The code above appears to kick off two separate events, one being the 'open/save dialogue' and the other being 'open in adobe' event. Having said that...* I went back and looked again and I think I Paolo had it right .*.. import os import sys pdf = receipt_PDF() pdf.add_page() rcpt_filename = "RCPT_%s_%s.pdf" % (session.rcpt_number, session.rcpt_recipient) rcpt_filename = rcpt_filename.replace( ' ', '_' ) rcpt_filename = rcpt_filename.replace( '&', 'and' ) # TODO read somewhere there is a 'clean' option in web2py for filepath? rcpt_filepath = request.folder + 'static/temp/%s'%(rcpt_filename) # Note I have removed leading '/' - long story! s_io = pdf.output(dest='S') response.headers['Content-Type']='application/pdf' response.headers['Content-Disposition'] = 'attachment; filename="%s"' % rcpt_filename raise HTTP(200, s_io, **response.headers) This is doing exactly what I want - the difference being I have removed the xdg open request (no static/temp file creation needed if dealing with a stringio object ). I need to play with it a bit more because it is now opening a 'download dialogue' which is perfect! (as opposed to 'open/save' dialogue) This is probably because I changed the system download options while investigating, so I need to go back over it to be sure. It does raise another question - did I not read that downloading a stringio is not recommended or was it just response.stream a stringio objectis not recommended - is there a diff? When I have finished checking it out I will post to confirm this is the solution and thanks again guys for your assistance! Peter -- 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.