Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving Files with Pyramid

I am serving quite large files from a Pyramid Application I have written. My only problem is download managers don't want to play nice.

I can't get resume downloading or segmenting to work with download manager like DownThemAll.

size = os.path.getsize(Path + dFile)
response = Response(content_type='application/force-download', content_disposition='attachment; filename=' + dFile)
response.app_iter = open(Path + dFile, 'rb')
response.content_length = size

I think the problem may lie with paste.httpserver but I am not sure.

like image 754
Krayons Avatar asked Nov 20 '11 11:11

Krayons


2 Answers

Pyramid 1.3 adds new response classes, FileResponse and FileIter for manually serving files.

like image 50
ZcMander Avatar answered Sep 24 '22 01:09

ZcMander


The web server on the python side needs to support partial downloads, which happens through the HTTP Accept-Ranges header. This blog post digs a bit into this matter with an example in python:

  • Python sample: Downloading file through HTTP protocol with multi-threads
like image 42
miku Avatar answered Sep 23 '22 01:09

miku