MarkReedZ / mrhttp

The fastest python web framework - 8.5m requests per second!
MIT License
24 stars 6 forks source link

File upload isn't working #16

Closed ShabazAlex closed 5 years ago

ShabazAlex commented 5 years ago

curl -i -X POST -F "data=@tst.py" http://localhost:8080/

@app.route('/')
async def index(r):
  print(r.files)
  return "indeX"

SystemError: <built-in method write of _io.TextIOWrapper object at 0x7f0be1ef0630> returned a result with an error set

MarkReedZ commented 5 years ago

I've fixed upload handling and modified the handling. Now when a file is uploaded you can access it via request.file or if multiple files are uploaded they will be in a list available from request.files.

I've also added this example code as examples/14_upload.py

from mrhttp import app

@app.route('/')
def hello(r):
  if r.file == None:
    return "No file uploaded"
  #for f in r.files:
    #print(f)
  name = r.file['name']
  typ  = r.file['type']
  body = r.file['body']
  return name

app.run(cores=4)

# curl -i -X POST -F "data=@14_upload.py" http://localhost:8080/