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

How to upload a file? #60

Open
matecsaj opened this issue Oct 22, 2022 · 3 comments
Open

How to upload a file? #60

matecsaj opened this issue Oct 22, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@matecsaj
Copy link
Owner

Swagger with OpenAPI contracts from eBay generate the core of this library, and they are not currently able to accept a path-file. Please ask eBay to solve the root problem; many voices will convince them of the need to act.

To learn more search in the Unit Tests for 'sell_feed_upload_file'.

Workarounds are suggested in the ReadMe search for 'How to upload a file?'.

@matecsaj matecsaj added bug Something isn't working help wanted Extra attention is needed labels Oct 22, 2022
@matecsaj
Copy link
Owner Author

Citing John

I might be able to automate your patches. The generator I wrote already does various patches before and after running Swagger to permanently fix some known problems.
https://github.com/matecsaj/ebay_rest/blob/main/scripts/generate_code.py

After you make your modifications, please send me the before and after files. To make this more viable, please:

  1. Repurpose existing KW arguments; for example, use the filename parameter of the file upload command to pass in the fullpath+filename+extension.
  2. Don’t delete or modify existing lines of Python code; insert new blocks of code where needed.
  3. Minimize the number of change locations.
  4. Note that when there is a choice, it is almost always more reliable to patch the OpenAPI contract rather than the Python Code that Swagger generates.

Citing Wang

I didn't really download the ebay_rest library, I just learning it before use it in product, but I could not understand how the upload_file works because I could not find the code it actually open/read the file, again I never wrote a test code to verify if it works or not.

For the patch, I suggest this

In file https://github.com/matecsaj/ebay_rest/blob/main/src/ebay_rest/api/sell_feed/api/task_api.py#L642

after Line 615 local_var_files = {}

append following code

local_var_files = {params.get('name'): params.get('file_name')}

Again I never downloaded this library so I just feel it should work.

@matecsaj matecsaj removed the help wanted Extra attention is needed label Nov 14, 2022
@andreinl
Copy link
Contributor

After a few days of trying this is the code that works:

test_file = open(file_name, 'rb').read()
result = api.sell_feed_upload_file(
    file=(file_name, test_file),
    content_type="multipart/form-data",
    task_id=task_id,
    type='form-data',
    file_name=file_name,
)

To make it work you need to add e few lines in sell_feed/api/task_api.py to make upload_file_with_http_info() aware of the 'file' attribute:

somewhere after the line 602:
all_params.append('file')

and after the line 652:

if 'file' in params:
    form_params.append(('file', params['file']))  # noqa: E501

@matecsaj
Copy link
Owner Author

Once again, thank you! I'm intensely working on another project, so please forgive me for letting this be for several weeks. If you need a fresh release with this change sooner or are willing to submit a PR, please use scripts/generate_code.py to patch sell_feed/api/task_api.py and provide a unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants