Thanks a lot, Jan. It worked!!

there is a typo in your return though. Should be file_content.

thanks again!

On Thu, Nov 21, 2013 at 7:52 AM, Jan Pipek <jan.pi...@gmail.com> wrote:
> 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
>> <cdv...@gmail.com> 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 webpy+un...@googlegroups.com.
>> > To post to this group, send email to we...@googlegroups.com.
>> > 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 webpy+unsubscr...@googlegroups.com.
> To post to this group, send email to webpy@googlegroups.com.
> 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 webpy+unsubscr...@googlegroups.com.
To post to this group, send email to webpy@googlegroups.com.
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