diff --git a/fasthtml/core.py b/fasthtml/core.py
index 780f4862..6291d46e 100644
--- a/fasthtml/core.py
+++ b/fasthtml/core.py
@@ -96,7 +96,7 @@ def _fix_anno(t):
origin = get_origin(t)
if origin is Union or origin is UnionType or origin in (list,List):
t = first(o for o in get_args(t) if o!=type(None))
- d = {bool: str2bool, int: str2int, date: str2date}
+ d = {bool: str2bool, int: str2int, date: str2date, UploadFile: noop}
res = d.get(t, t)
if origin in (list,List): return partial(_mk_list, res)
return lambda o: res(o[-1]) if isinstance(o,(list,tuple)) else res(o)
diff --git a/nbs/api/00_core.ipynb b/nbs/api/00_core.ipynb
index 715bec84..bd3ad2c0 100644
--- a/nbs/api/00_core.ipynb
+++ b/nbs/api/00_core.ipynb
@@ -129,7 +129,7 @@
{
"data": {
"text/plain": [
- "datetime.datetime(2024, 9, 24, 14, 0)"
+ "datetime.datetime(2024, 10, 10, 14, 0)"
]
},
"execution_count": null,
@@ -363,7 +363,7 @@
" origin = get_origin(t)\n",
" if origin is Union or origin is UnionType or origin in (list,List):\n",
" t = first(o for o in get_args(t) if o!=type(None))\n",
- " d = {bool: str2bool, int: str2int, date: str2date}\n",
+ " d = {bool: str2bool, int: str2int, date: str2date, UploadFile: noop}\n",
" res = d.get(t, t)\n",
" if origin in (list,List): return partial(_mk_list, res)\n",
" return lambda o: res(o[-1]) if isinstance(o,(list,tuple)) else res(o)"
@@ -1441,6 +1441,16 @@
" return f(path) if callable(path) else f"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a82b103f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%ai reset"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -2196,6 +2206,42 @@
"test_eq(response, '{\"b\": \"Lorem\", \"a\": 15}')"
]
},
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4034ee37",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "files = [ ('files', ('file1.txt', b'content1')),\n",
+ " ('files', ('file2.txt', b'content2')) ]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "04881594",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "200\n",
+ "content1,content2\n"
+ ]
+ }
+ ],
+ "source": [
+ "@rt(\"/uploads\")\n",
+ "async def post(files:list[UploadFile]):\n",
+ " return ','.join([(await file.read()).decode() for file in files])\n",
+ "\n",
+ "res = cli.post('/uploads', files=files) \n",
+ "print(res.status_code)\n",
+ "print(res.text)"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -2206,13 +2252,13 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "Set to 2024-09-24 15:25:23.127900\n"
+ "Set to 2024-10-10 04:51:50.335203\n"
]
},
{
"data": {
"text/plain": [
- "'Session time: 2024-09-24 15:25:23.127900'"
+ "'Session time: 2024-10-10 04:51:50.335203'"
]
},
"execution_count": null,