Skip to content

Instantly share code, notes, and snippets.

@metatoaster
Created September 4, 2013 03:25
Show Gist options
  • Save metatoaster/6432448 to your computer and use it in GitHub Desktop.
Save metatoaster/6432448 to your computer and use it in GitHub Desktop.
ZPublisher filestream_iterator example
import os
import stat
from ZPublisher.Iterators import filestream_iterator
from zope.publisher.browser import BrowserPage
class FilestreamPage(BrowserPage):
target = '/path/to/some/file'
def __call__(self):
size = os.stat(self.target)[stat.ST_SIZE]
self.request.response.setHeader('Content-type',
'application/octet-stream')
self.request.response.setHeader('Content-length', int(size))
return filestream_iterator(self.target, 'rb')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment