This code is pretty simple and is a example, but is painfully slow for big 
files (10Mb)!

How to read data chunks of request body to a temp file instead of reading 
everything at once to memory?
    
    
    import asynchttpserver, asyncdispatch
    
    proc handler(req: Request) {.async.} =
        echo req.url.path
        if req.reqMethod == HttpPost:
            echo req.headers
            echo req.body.len
            echo req.body
        
        var form = """
    <html>
    <body>
    <form action="/server" method="post" enctype="multipart/form-data">
      <input type="file" name="textfile" accept="text/*"><br />
      <input type="submit">
    </form>
    </body>
    </html>
    """
        
        await req.respond(Http200, form)
    
    var server = newAsyncHttpServer(maxBody=16777216)
    waitFor server.serve(Port(8080), handler)
    
    
    Run

Reply via email to