-
Notifications
You must be signed in to change notification settings - Fork 63
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
Cannot upload a binary file via when using multipart
and Part
#180
Comments
Hello, I'm fairly new to this package so I'm using the Petstore Swagger API to practice. Unfortunately, I'm also trying to upload a file but I'm unsure on how to do so. I'm able to execute 1 call (add pet to petstore -> in order to get a pet_id), but I'm unable to upload a file using multipart (uploadFile). When I call uploadFile, I get the following message: A successful request returns the following response: As such, I was wondering if you could please help and share what the proper way of uploading a file and structuring the Pets class is, for the class that I created using Uplink? Thank you! |
@joeld1 - The file upload behavior you are encountering may be caused by an issue identified in #183. Can you try adding the workaround mentioned in #183 (comment) to your script? |
I've tried using the workaround mentioned here #183 (comment) edit: i am able to send a file with the appropriate content-type if I pass in a tuple that edit 2: realized I didn't share my workaround with my last update, here it is for others. also interested @prkumar in your thoughts on the content-type per part. from mimetypes import guess_type
from uplink.converters import StandardConverter
from uplink import (
Consumer,
Part,
post,
multipart,
returns,
headers,
)
def pass_through_request_body_converter(self, type_, *args, **kwargs):
return lambda value: value
StandardConverter.create_request_body_converter = pass_through_request_body_converter
@headers({"Accept": "application/json"})
class BlobClient(Consumer):
def post_blob(self, blob_fp, something_interesting):
blob_type, _ = guess_type(blob_fp.name)
return self._post_blob(
(blob_fp.name, blob_fp, blob_type), something_interesting
)
@multipart
@returns.json
@post("/")
def _post_blob(self, blob: Part, something_interesting: Part):
pass
... |
Describe the bug
Uplink throws an exception when trying to send a binary file using the
multipart
decorator:To Reproduce
Expected behavior
This should be the equivalent of the following requests code (which works):
When trying to implement a suggested workaround:
I get a different error:
Additional context
Using uplink 0.9.0
The text was updated successfully, but these errors were encountered: