2

我想使用 Suave 上传文件。我知道小文件会自动写入/tmp文件夹,但我的文件太大了。我想做的是将它们作为处理并通过 Suave 服务器将它们发送到长期存储。

这是我的服务器:

#r "nuget: Suave"

open System.IO
open Suave
open Suave.Sockets
open Suave.Sockets.Control

let config = defaultConfig

let socketTask (conn : Connection, httpResult : HttpResult) =
  socket {
    printfn "Started socket task"

    use stream = new TransportStream (conn.transport)
    use reader = new StreamReader (stream)

    while not reader.EndOfStream do
      printfn "Reading... "

      let! line = SocketOp.ofAsync (async {
        let! line = reader.ReadLineAsync ()
        return line
      })

      printfn "%s" line

    printfn "Finished socket task"

    return conn
  }

let app : WebPart =
  (fun ctx -> async {
    printfn "Received request"

    return
      Some
        {
          ctx with
            response =
              {
                ctx.response with
                  content = SocketTask socketTask
              }
        }
  })

startWebServer config app

但是当我运行这个curl命令时,它只是挂起:

$ curl -X POST --data-binary @big-file.csv localhost:8080
$ dotnet fsi ./Suave.fsx
[17:32:05 INF] Smooth! Suave listener started in 14.279ms with binding 127.0.0.1:8080
Received request
Started socket task

我希望上传的文件能够逐行打印。

我在这里想念什么?

4

0 回答 0