Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File parameter doesn't propagate the file name #201

Open
diegodelemos opened this issue Oct 12, 2017 · 2 comments
Open

File parameter doesn't propagate the file name #201

diegodelemos opened this issue Oct 12, 2017 · 2 comments

Comments

@diegodelemos
Copy link

diegodelemos commented Oct 12, 2017

I am wondering if you had in mind when you designed add_file that you are naming the file after the spec parameter name in bravado_core/param.py.
Given this parameter spec:

{
    "type": "file",
    "in": "formData",
    "name": "photo"
}

Here in bravado_core/param.py:

> file_tuple = (param.name, (param.name, value))
> print(param.name)
'photo'

So when you receive this file in the server (i.e. Flask) you end up with something like this:

> f = request.files['photo']
> print(f.filename)
'photo'

However, what one would expect would be something like:

> f = request.files['photo']
> print(f.filename)
'pisa_tower.png'

For doing so, something like the following would be needed:

--- a/bravado_core/param.py
+++ b/bravado_core/param.py
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+import os
 import logging
 from functools import partial

@@ -284,7 +285,8 @@ def add_file(param, value, request):
                     param.op.consumes
             ))

-    file_tuple = (param.name, (param.name, value))
+    _, file_name = os.path.split(value.name)
+    file_tuple = (param.name, (file_name, value))
     request['files'].append(file_tuple)

👍 to @prat0318 comment in #53

I am wondering if add_file should throw up if value is not of file type instead of just ignoring it (as per the PR).

But it would change some of the existing tests since you are using StringIO to generate files which doesn't implement fully file object interface (attributes such as name are missing)

The question is, would it be feasible to do such a change? If so I would volunteer to make a PR and amend tests.

diegodelemos pushed a commit to diegodelemos/reana-server that referenced this issue Oct 12, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-workflow-controller that referenced this issue Oct 12, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-client that referenced this issue Oct 12, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-client that referenced this issue Oct 12, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-server that referenced this issue Oct 19, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-client that referenced this issue Oct 19, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-server that referenced this issue Oct 19, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
diegodelemos pushed a commit to diegodelemos/reana-server that referenced this issue Oct 19, 2017
* Adds a redundant field `file_name` since bravado client doesn't
  propagate the file name. Waiting for Yelp/bravado-core#201 to be
  implemented.

Signed-off-by: Diego Rodriguez <[email protected]>
@valp124
Copy link

valp124 commented Mar 28, 2018

Facing the same problem. Any ETA on the fix?

@anglvictor
Copy link

still having this issue, is there any work around for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants