diff --git a/api/api.py b/api/api.py index 508f7bc32ba7f7b154f0047c32e7f4e1c92fcdde..54e06b10fadb6fbf45f0481abda6f1d5d4d5f512 100644 --- a/api/api.py +++ b/api/api.py @@ -143,7 +143,7 @@ endpoints = [ ]), route('/gears', GearsHandler), route('/gears/temp', GearHandler, h='upload', m=['POST']), - route('/gears/temp/<cid:{cid}>', GearHandler, h='download', m=['GET']), + route('/gears/temp/<cid:{cid}>', GearHandler, h='download', m=['GET']), prefix('/gears', [ route('/<:[^/]+>', GearHandler), route('/<:[^/]+>/invocation', GearHandler, h='get_invocation'), diff --git a/api/jobs/handlers.py b/api/jobs/handlers.py index 0fc2c8f72acc37ee2773e5c2b3614022188e388a..03209b9c8db905d269b5e1d73520c9b28c62a30b 100644 --- a/api/jobs/handlers.py +++ b/api/jobs/handlers.py @@ -3,10 +3,12 @@ API request handlers for the jobs module """ import bson import json +import os import StringIO from jsonschema import ValidationError from .. import upload +from .. import util from ..auth import require_login, has_access from ..dao import APIPermissionException from ..dao.containerstorage import AcquisitionStorage @@ -73,7 +75,7 @@ class GearHandler(base.RequestHandler): # Temporary Function def upload(self): - """Upload new gear file""" + """Upload new gear tarball file""" if not self.user_is_admin: self.abort(403, 'Request requires admin') @@ -83,8 +85,18 @@ class GearHandler(base.RequestHandler): # Temporary Function def download(self, **kwargs): + """Download gear tarball file""" + if not self.user_is_admin: + self.abort(403, 'Request requires admin') + dl_id = kwargs.pop('cid') - return {'_id':str(dl_id)} + gear = get_gear(dl_id) + hash_ = gear['hash'] + filepath = os.path.join(config.get_item('persistent', 'data_path'), util.path_from_hash(hash_)) + self.response.app_iter = open(filepath, 'rb') + self.response.headers['Content-Length'] = str(gear['size']) # must be set after setting app_iter + self.response.headers['Content-Type'] = 'application/octet-stream' + self.response.headers['Content-Disposition'] = 'attachment; filename="' + gear['filename'] + '"' def post(self, _id):