Skip to content

Commit

Permalink
Accept serialized Tale in POST /tale/import
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed Mar 27, 2019
1 parent 59559c2 commit 7815aad
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion server/rest/tale.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cherrypy
from datetime import datetime, timedelta
import time
import tempfile

from girder.api import access
from girder.api.rest import iterBody
from girder.api.docs import addModel
from girder.api.describe import Description, autoDescribeRoute
from girder.api.rest import Resource, filtermodel, RestException,\
Expand Down Expand Up @@ -169,7 +173,11 @@ def deleteTale(self, tale, progress):
@autoDescribeRoute(
Description('Create a new tale from an external dataset.')
.notes('Currently, this task only handles importing raw data. '
'In the future, it should also allow importing serialized Tales.')
'A serialized Tale can be sent as the body of the request using an '
'appropriate content-type and with the other parameters as part '
'of the query string. The file will be stored in a temporary '
'space. However, it is not currently being processed in any '
'way.')
.param('imageId', "The ID of the tale's image.", required=True)
.param('url', 'External dataset identifier.', required=True)
.param('spawn', 'If false, create only Tale object without a corresponding '
Expand All @@ -189,6 +197,15 @@ def createTaleFromDataset(self, imageId, url, spawn, lookupKwargs, taleKwargs):
token = self.getCurrentToken()
Token().addScope(token, scope=REST_CREATE_JOB_TOKEN_SCOPE)

if cherrypy.request.body.length > 0:
with tempfile.NamedTemporaryFile() as fp:
for chunk in iterBody(2 * 1024 ** 3):
fp.write(chunk)
fp.seek(0)
# TODO: check if zip, check if Tale
# shortcircut here either by running a separate job
# or modifying import_tale to grab a file

try:
lookupKwargs['dataId'] = [url]
except TypeError:
Expand Down

0 comments on commit 7815aad

Please sign in to comment.