def download()

in source/api/app.py [0:0]


def download(filesystem_id):
    """
    Downloads a file

    :param filesystem_id: The filesystem to perform operation on
    :param path: The path to download the file
    :param filename: The name of the file
    :returns: Filesystem operation response
    :raises ChaliceViewError, BadRequestError
    """
    print(app.current_request.query_params)
    try:
        path = app.current_request.query_params['path']
        filename = app.current_request.query_params['filename']
    except KeyError as error:
        app.log.error('Missing required query param: {e}'.format(e=error))
        raise BadRequestError('Missing required query param: {e}'.format(e=error))
    else:
        if 'dzchunkindex' and 'dzchunkbyteoffset' in app.current_request.query_params:
            chunk_index = app.current_request.query_params['dzchunkindex']
            chunk_offset = app.current_request.query_params['dzchunkbyteoffset']
            filemanager_event = {"operation": "download", "path": path, "filename": filename, \
                                 "chunk_data": {"dzchunkindex": int(chunk_index), \
                                     "dzchunkbyteoffset": int(chunk_offset)}}
            operation_result = proxy_operation_to_efs_lambda(filesystem_id, filemanager_event)
            payload_encoded = operation_result['Payload']
            payload = json.loads(payload_encoded.read().decode("utf-8"))
            return payload
        elif 'dzchunkindex' and 'dzchunkbyteoffset' not in app.current_request.query_params:
            filemanager_event = {"operation": "download", "path": path, "filename": filename}
            operation_result = proxy_operation_to_efs_lambda(filesystem_id, filemanager_event)
            payload_encoded = operation_result['Payload']
            payload = json.loads(payload_encoded.read().decode("utf-8"))
            return payload
        else:
            raise BadRequestError('Unsupported or missing query params')