vinissimus / async-asgi-testclient

A framework-agnostic library for testing ASGI web applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File uploading error

otsuka opened this issue · comments

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

I'll try to fix it tonight :)

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

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

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

Yay! 🎉