Вот пример из документации по aiohttp, дополненный для самодостаточности:
from aiohttp import web
import os
async def form(request):
return web.Response(text="""<html>
<form action="/store/mp3" method="post" accept-charset="utf-8"
enctype="multipart/form-data">
<label for="mp3">Mp3</label>
<input id="mp3" name="mp3" type="file" value=""/>
<input type="submit" value="submit"/>
</form></html>""", content_type='text/html')
async def store_mp3_handler(request):
reader = await request.multipart()
# /!\ Don't forget to validate your inputs /!\
# reader.next() will `yield` the fields of your form
field = await reader.next()
assert field.name == 'mp3'
filename = field.filename
# You cannot rely on Content-Length if transfer is chunked.
size = 0
with open(os.path.join('mp3/', filename), 'wb') as f:
while True:
chunk = await field.read_chunk() # 8192 bytes by default.
if not chunk:
break
size += len(chunk)
f.write(chunk)
return web.Response(text='''
{} sized of {} successfully stored in
<a href="/mp3">/mp3/</a>'''.format(filename, size),
content_type='text/html')
os.makedirs('mp3/', exist_ok=True)
app = web.Application()
app.add_routes([web.static('/mp3', 'mp3/', show_index=True)])
app.add_routes([web.get('/', form)])
app.add_routes([web.post('/store/mp3', store_mp3_handler)])
web.run_app(app)
Установить aiohttp:
python3 -m pip install aiohttp
А просто раздать папку на питоне можно без кода и дополнительных библиотек
python3 -m http.server
socket
,flask
,cgi
,django
,bottle
,wsgi
...