Hello,

I think you want something like this.

from paste.fileapp import FileApp

#.... in controller ....
        #...in some action, get the path to serve
        wsgi_app = FileApp(path)
        return wsgi_app(request.environ, self.start_response)

A better solution you might want to look into is x-sendfile/x-accel-redirect
which let's you pass the path up to a proxying server via a header that it
can use to serve the file.  That way you can check permissions in your app
but still serve the file via apache/nginx/etc.

-Ian


On Wed, Jul 21, 2010 at 12:27 PM, Jens Hoffrichter <
[email protected]> wrote:

> Hi everyone,
>
> I looked into the documentation, but couldn't find any mentioning of
> what I could return from an action.
>
> I know that I can return a string, most likely rendered from a template.
>
> Is it possible to return a file object from an action, so that the
> contents of the file will be delivered to receiving end?
>
> I need to pass images through a controller, because I need to check if
> the user is allowed to see the requested picture - so I can't make use
> of the Apache of delivering the files myself. Up until now, I've
> always read such files into memory, and just returned the contents,
> but these images might be a bit bigger than what I'm used to with
> dealing with, so this might be a useful function, to reduce memory
> usage on my app.
>
> Thanks in advance for any advice on this!
>
> Regards,
> Jens
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<pylons-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to