File uploading error
otsuka opened this issue · comments
otsuka commented
I'd like to test uploading files to API server.
Using your test client, I wrote the test as below:
with (datadir / "image.png").open("rb") as fp:
files = {"image": ("sample.png", fp, "image/png")}
response = await client.post("/api/upload_image", files=files)
But multipart file handling seems to have some error.
I don't think that decoding binary data of a file into str is possible.
if isinstance(value, bytes):
> value = value.decode("ascii")
E UnicodeDecodeError: 'ascii' codec can't decode byte 0x89 in position 0: ordinal not in range(128)
../../../../../.venv/lib/python3.7/site-packages/async_asgi_testclient/multipart.py:59: UnicodeDecodeError
Jordi Masip commented
I'll try to fix it tonight :)
Jordi Masip commented
Fix released on v1.4.1. Please confirm me that is working now
otsuka commented
Thank you very much! 👍
I will try it later on.
otsuka commented
I have confirmed that an image file can be uploaded from the TestClient.post() method 🎉
Jordi Masip commented
Yay! 🎉