Created
September 4, 2013 03:25
-
-
Save metatoaster/6432448 to your computer and use it in GitHub Desktop.
ZPublisher filestream_iterator example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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