On Fri, Dec 16, 2011 at 2:24 PM, Kyle Welsh <[email protected]> wrote: > Hi all, > > Trying to get my pyramid app to support partial and multi-threaded HTTP > downloads. > > This is what I have managed to come up with so far but it is still not > working. > > Any insights into what I am doing wrong would be great. > > def download(request): > try: > bytes = request.GET['Accept-Ranges'] > size = os.path.getsize('/home/kyle/test.bin') > f = open('/home/kyle/test.bin', 'rb') > f.seek(bytes) > response = Response(content_type='application/force-download', > content_disposition='attachment; filename=test.bin') > response.app_iter = f > response.accept_ranges = 'bytes' > response.content_length = size > except KeyError: > size = os.path.getsize('/home/kyle/test.bin') > response = Response(content_type='application/force-download', > content_disposition='attachment; filename=test.bin') > response.app_iter = open('/home/kyle/test.bin', 'rb') > response.accept_ranges = 'bytes' > response.content_length = size > return response >
Here's an example of a response object that serves a file from the filesystem and can handle Range requests: https://bitbucket.org/chrisrossi/happy/src/f2ab316ad673/happy/static.py Chris -- 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.
