예제 #1
0
def app_read_body(environ, start_response):
    request = Request(environ)
    data = request.form
    output = {}
    for key, value in data.items():
        output[key] = value
    request.close()
    response = JSONResponse(output)
    return response(environ, start_response)
예제 #2
0
 def app(environ, start_response):
     request = Request(environ)
     form = request.form
     file = form["file-key"]
     assert isinstance(file, UploadFile)
     assert file.read() == b"temporary file"
     response = JSONResponse({"file": file.filename})
     request.close()
     return response(environ, start_response)
예제 #3
0
def app(environ, start_response):
    request = Request(environ)
    data = request.form
    output = {}
    for key, value in data.items():
        if isinstance(value, UploadFile):
            content = value.read()
            output[key] = {
                "filename": value.filename,
                "content": content.decode(),
                "content_type": value.content_type,
            }
        else:
            output[key] = value
    request.close()
    response = JSONResponse(output)
    return response(environ, start_response)
예제 #4
0
def multi_items_app(environ, start_response):
    request = Request(environ)
    data = request.form
    output = {}
    for key, value in data.multi_items():
        if key not in output:
            output[key] = []
        if isinstance(value, UploadFile):
            content = value.read()
            output[key].append({
                "filename": value.filename,
                "content": content.decode(),
                "content_type": value.content_type,
            })
        else:
            output[key].append(value)
    request.close()
    response = JSONResponse(output)
    return response(environ, start_response)
예제 #5
0
 def app(environ, start_response):
     request = Request(environ)
     form = request.form
     response = JSONResponse({"form": dict(form)})
     return response(environ, start_response)
     request.close()