app = Klein()

@app.route('/')
def formpage(request):
    return """
    <form action="/images" enctype="multipart/form-data" method="post">
    <p>
        Please specify a file, or a set of files:<br>
        <input type="file" name="datafile" size="40">
    </p>
    <div>
        <input type="submit" value="Send">
    </div>
    </form>
    """

@app.route('/images', methods=['POST'])
def processImages(request):
    method = request.method.decode('utf-8').upper()
content_type = request.getHeader('content-type')
img = FieldStorage(fp=request.content, headers=request.getAllHeaders(),
    environ={'REQUEST_METHOD': method, 'CONTENT_TYPE': content_type})
name = secure_filename(img['datafile'].filename)
with open(name, 'wb') as fileOutput:
    fileOutput.write(request.args['datafile'][0])
app.run('localhost', 8000)
How to receive uploaded file with Klein like Flask in python