AkkaHTTP:如何在使用mutlpart上传时从路径访问捕获的值(实体(作为[Multipart.FormData]))

时间:2016-05-19 12:04:19

标签: akka spray akka-stream akka-http

我试图在上传文件时尝试从路径访问捕获的值但无法了解实现。

以下是示例代码:

trait TestRoute extends {
  val regEx = """(\w+)""".r
  def testRoute: Route = path("testing" / regEx / regEx / regEx){
    post {
      //How do i Access (captured regex from the path) inside entity
      entity(as[Multipart.FormData]) { fileData => {
        complete {
           "UpLoadDOne"
        }  
       }
    }
   }
}           

http://localhost:9000/testing/A/B/C

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

如果使用喷雾剂,则需要以下内容:

import spray.routing.PathMatchers.Segment

trait TestRoute extends {

  def testRoute: Route = path("testing" / Segment / Segment / Segment){ case (A, B, C) =>
    post {
      entity(as[Multipart.FormData]) { fileData =>
        complete {
          "UpLoadDOne"
        }
      }
    }
  }