Skip to content
Snippets Groups Projects
Commit b93d49a1 authored by Gunnar Schaefer's avatar Gunnar Schaefer
Browse files

add streaming downloads

parent efb2d400
No related branches found
No related tags found
No related merge requests found
...@@ -195,11 +195,14 @@ class Container(base.RequestHandler): ...@@ -195,11 +195,14 @@ class Container(base.RequestHandler):
self.abort(404, 'no such file') self.abort(404, 'no such file')
filename = file_info['name'] + file_info['ext'] filename = file_info['name'] + file_info['ext']
filepath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), filename) filepath = os.path.join(self.app.config['data_path'], str(_id)[-3:] + '/' + str(_id), filename)
ticket = util.download_ticket('single', filepath, filename, file_info['size'])
tkt_id = self.app.db.downloads.insert(ticket)
if self.request.method == 'GET': if self.request.method == 'GET':
self.redirect_to('download', _abort=True, ticket=tkt_id) self.response.app_iter = open(filepath, 'rb')
return {'url': self.uri_for('download', _full=True, ticket=tkt_id)} self.response.headers['Content-Length'] = str(file_info['size']) # must be set after setting app_iter
self.response.headers['Content-Type'] = 'application/octet-stream'
else:
ticket = util.download_ticket('single', filepath, filename, file_info['size'])
tkt_id = self.app.db.downloads.insert(ticket)
return {'url': self.uri_for('download', _full=True, ticket=tkt_id)}
def put_file(self, cid=None): def put_file(self, cid=None):
""" """
...@@ -328,12 +331,14 @@ class Container(base.RequestHandler): ...@@ -328,12 +331,14 @@ class Container(base.RequestHandler):
break break
else: else:
self.abort(404, 'no such file') self.abort(404, 'no such file')
ticket = util.download_ticket('single', fpath, fname, a_info['size'])
tkt_id = self.app.db.downloads.insert(ticket)
if self.request.method == 'GET': if self.request.method == 'GET':
self.redirect_to('download', _abort=True, ticket=tkt_id) self.response.app_iter = open(fpath, 'rb')
return {'url': self.uri_for('download', _full=True, ticket=tkt_id)} self.response.headers['Content-Length'] = str(a_info['size']) # must be set after setting app_iter
self.response.headers['Content-Type'] = 'application/octet-stream'
else:
ticket = util.download_ticket('single', fpath, fname, a_info['size'])
tkt_id = self.app.db.downloads.insert(ticket)
return {'url': self.uri_for('download', _full=True, ticket=tkt_id)}
def delete_attachment(self, cid): def delete_attachment(self, cid):
"""Delete one attachment.""" """Delete one attachment."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment