Skip to content

Commit

Permalink
Merge pull request #131 from pka/patch-2
Browse files Browse the repository at this point in the history
Document request.inputs access with index
  • Loading branch information
jachym authored Jun 26, 2016
2 parents d571361 + 8d80f0d commit bb6ed6d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/process.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,25 @@ values are found in the `inputs` dictionary::

@staticmethod
def _handler(request, response):
name = request.inputs['name'].data
name = request.inputs['name'][0].data
response.outputs['output'].data = 'Hello world %s!' % name
return response

`inputs` is a plain Python dictionary.
Input can be set and read in different ways including as a file, as data
- like string or numbers - or as a stream::

request.inputs['file_input'].file
request.inputs['data_input'].data
request.inputs['stream_input'].stream
request.inputs['file_input'][0].file
request.inputs['data_input'][0].data
request.inputs['stream_input'][0].stream

Because there could be multiple input values with the same identifier, the inputs are accessed with an index.
For `LiteralInput`, the value is a string. For `ComplexInput`, the value
is an open file object, with a `mime_type` attribute::

@staticmethod
def handler(request, response):
layer_file = request.inputs['layer'].file
layer_file = request.inputs['layer'][0].file
mime_type = layer_file.mime_type
bytes = layer_file.read()
msg = ("You gave me a file of type %s and size %d"
Expand Down

0 comments on commit bb6ed6d

Please sign in to comment.