Skip to content

Instantly share code, notes, and snippets.

@format37
Last active November 4, 2020 13:40
Show Gist options
  • Save format37/093ef14a2f4bfcdf73c26988a83795e4 to your computer and use it in GitHub Desktop.
Save format37/093ef14a2f4bfcdf73c26988a83795e4 to your computer and use it in GitHub Desktop.
python aiohttp post send and receive file
import requests
url = 'http://SERVER_ADDRESS:PORT/sendfile'
files = {'file': open('data.txt', 'r').read()}
requests.post(url, data=files)
from aiohttp import web
PORT = 8082
async def send_file(request):
data = await request.post()
with open('data.txt', 'w') as f:
f.write(data['file'])
return web.Response(text='ok',content_type="text/html")
app = web.Application(client_max_size=1024**3)
app.router.add_post('/sendfile', send_file)
web.run_app(app,port=PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment