Hi Claudio,
sending something "as a file" is really easy (assuming the file is 
reasonably small). You just set the correct HTTP headers and sent the 
content:

class YourAction
 def GET(self, ...):
   ...
   web.header('Content-Type', mime_type)
   web.header('Content-Length', len(fIle_content))
   web.header('Content-Disposition', 'attachment; filename="%s"' % 
(file_name))
   return content

where `file_content` is the content of the file, `mime_type` its MIME type 
(if known) and `file_name` is whatever name you want the browser to think 
the file has (doesn't necessary have to be the same as on your filesystem).

`file_content` you easily obtain like this (there are more ways for sure):

with open('Path/to/file', 'r') as f:
   file_content = f.read()

Hope this helps.
Cheers,
Jan



On Wednesday, 20 November 2013 17:10:04 UTC+1, Claudio Dusan Vega 
Ozuljevich wrote:
>
> in my template a got a link that redirects to a GET which validates 
> the user and file, now the specific question is: 
>
> how to send the file to the user? 
>
> ps: sorry for no subject, didnt notice. 
>
> On Wed, Nov 20, 2013 at 12:13 PM, Claudio Dusan Vega Ozuljevich 
> <[email protected] <javascript:>> wrote: 
> > Hi guys! 
> > 
> > I'm developing a web app which stores files (pictures, pdf) in disk 
> > and now I need to create a link (in a template) from which the data 
> > can be downloaded in case that the user owns the file (so I need to 
> > validate). 
> > 
> > How to do this? I looked at the doc and found nothing. 
> > 
> > Thanks in advance! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "web.py" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to [email protected] <javascript:>. 
> > To post to this group, send email to [email protected]<javascript:>. 
>
> > Visit this group at http://groups.google.com/group/webpy. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to