vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications
MIT License
160 stars 20 forks source link

File uploading error #28

Closed otsuka closed 4 years ago

otsuka commented 4 years ago

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
masipcat commented 4 years ago

I'll try to fix it tonight :)

masipcat commented 4 years ago

Fix released on v1.4.1. Please confirm me that is working now

otsuka commented 4 years ago

Thank you very much! 👍 I will try it later on.

otsuka commented 4 years ago

I have confirmed that an image file can be uploaded from the TestClient.post() method 🎉

masipcat commented 4 years ago

Yay! 🎉