上传文件

概述

如果dealer的参数类型是UploadedFile,则这个参数就可接收前端上传的文件

UploadedFile对象的成员:

示例

example.py

from lessweb import Application, UploadedFile

def upload(f:UploadedFile, id:int):
    summary = f.value[:10] + b'...'
    return {'id':id, 'filename': f.filename, 'value': summary.decode(), 'size': len(f.value)}

app = Application()
app.add_post_mapping('/upload', dealer=upload)
app.run()

请求: curl -X POST --form id=6 --form f=@./example.py "http://localhost:8080/upload"
返回: {"id": 6, "filename": "example.py", "value": "from lessw...", "size": 317}