我试图在上传文件时尝试从路径访问捕获的值但无法了解实现。
以下是示例代码:
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
感谢您的帮助!
答案 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"
}
}
}
}