Skip to content

Commit cf1a706

Browse files
committed
Document passing file arguments
1 parent 17cf714 commit cf1a706

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

deepaas/model/v2/wrapper.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@
3535
CONF = cfg.CONF
3636

3737

38-
UploadedField = collections.namedtuple("UploadedField", ("name",
39-
"filename",
40-
"file",
41-
"content_type"))
38+
UploadedFile = collections.namedtuple("UploadedFile", ("name",
39+
"filename",
40+
"content_type"))
41+
"""Class to hold uploaded field metadata when passed to model's methods
42+
43+
.. py:attribute:: name
44+
45+
Name of the argument where this file is being sent.
46+
47+
.. py:attribute:: filename
48+
49+
Complete file path to the temporary file in the filesyste,
50+
51+
.. py:attribute:: content_type
52+
53+
Content-type of the uploaded file.
54+
"""
4255

4356

4457
class ModelWrapper(object):
@@ -249,15 +262,14 @@ def predict(self, *args, **kwargs):
249262
error, already wrapped as a HTTPException
250263
"""
251264
for key, val in kwargs.items():
252-
if isinstance(val, web.FileField):
265+
if isinstance(val, web.FileFile):
253266
fd, name = tempfile.mkstemp()
254267
fd = os.fdopen(fd, "w+b")
255268
fd.write(val.file.read())
256269
fd.close()
257-
aux = UploadedField(
270+
aux = UploadedFile(
258271
name=val.name,
259-
filename=val.filename,
260-
file=name,
272+
filename=name,
261273
content_type=val.content_type,
262274
)
263275
kwargs[key] = aux

doc/source/user/v2-api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ field created as follows::
127127
do not forget to add the ``location="form"`` and ``type="file"`` to the
128128
argument definition, otherwise it will not work as expected.
129129

130+
Once defined, you will receive an object of the class described below for each
131+
of the file arguments you declare. You can open and read the file stored in the
132+
``filename`` attribute.
133+
134+
.. autoclass:: deepaas.model.v2.wrapper.UploadedFile
135+
130136
Then you should define the ``predict`` function as indicated below. You will
131137
receive all the arguments that have been parsed as keyword arguments:
132138

0 commit comments

Comments
 (0)