The database field does not store the full download path -- only the filename. response.download() takes the request object and the db object and knows how to extract the filename from the request, find the associated table and field in the db, and then find the upload folder (which is an attribute of the field object) in order to construct the full file path. response.stream() does not do all that, so you have to provide it with the full path or an open file(-like) object. Anyway, you can just use response.download() instead:
def download(): return response.download(request, db, download_filename=request.args(1)) Anthony On Tuesday, October 15, 2013 5:04:06 PM UTC-4, Jordan Ladora wrote: > > Hello, > > I've got a table with files inserted into an upload field. Downloading > works fine when I pass the file path to the default download controller. > > <td>{{=A('Download', _href=URL('default', 'download', > args=download_path))}}</td> > > However, I'd like the user to be able to change only the name of the file > that is downloaded without having to do any file copying or additional > database inserts. Nor do I want to break web2py's file renaming system. I > want to allow for the possibility that the user might decide to rename the > file later on after they uploaded it by storing the new name and presenting > it at download time.. it seems like this can be done via response.stream > but I cannot make this happen.. > > I've tried these two strategies (and many modifications) but get errors, > 404 not found, or invalid requests... > > in the view- > > <td>{{=A('Download1', _href=URL('default', 'download1', > args=[download_path, 'new_title']))}}</td> > <td>{{=A('Download2', _href=URL('default', 'download2', > args=[download_path, 'new_title']))}}</td> > > > in the default controller- > > @auth.requires_login() > def download1(): > response.headers['Content-Type'] = "application/octet-stream" > response.headers['Content-Disposition'] = 'attachment; filename=%s' % > request.args(1) > > return response.stream(request.args(0)) > > > @auth.requires_login() > def download2(): > > return response.stream(request.args(0), attachment=True, > filename=request.args(1)) > > > > ...is this possible? Thanks in advance for help. > -j > > -- 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.