[Grok-dev] Get files
Wichert Akkerman
wichert at wiggy.net
Fri Mar 19 11:40:50 EDT 2010
On 3/19/10 16:33 , Sebastian Ware wrote:
> if you store files in src/[appname]/static they will be reachable with
>
> host:port/[app_instance_name]/@@/[appname]/path/relative/to/
> static.pdf
>
> You can also create a view that returns files you have stored on the
> filesystem:
>
> class Index(grok.View):
> grok.name('index.html')
> grok.require('zope.Public')
>
> def render(self):
> self.response.setHeader('Content-Disposition', 'inline')
You probably want to provide a filename with that header as well.
> self.response.setHeader('Content-Type',
> self.context.content_type)
> file = open('local/file/system/path.pdf', 'rb')
> data = file.read()
> file.close()
>
> return data
This works, but a performance killer when serving large files since
you'll keep a thread blocked during the download. You should to able to
return a file iterator instead.
Wichert.
More information about the Grok-dev
mailing list