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 Jun 6, 2019
1 parent 0d41d8d commit 91d63b9
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
import tempfile
import time

from girder import events
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 @@ -177,7 +181,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 @@ -197,6 +205,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 91d63b9

Please sign in to comment.