Internet上有大量文档如何以其他语言在HTTP POST请求中发送文件流,但在Scalatra中没有。
主题:我想通过 Scalatra post() 以字节数组或文件流的形式发送图像(对不起,草率的术语,我绝对是新手)。我已经有后端 Java 函数,它们采用字节数组,将其转换回 .jpg 图像并将其存储在服务器上。我不清楚的是如何在 Scalatra 中执行此操作的确切语法。
这就是我的帖子请求的样子:
val imageInBytes = ... //obtain image in bytes
post("/images", ("image" -> imageInBytes))
但是,Eclipse 说重载方法 post 不能应用于 (String, (String, Array[Byte]))
在服务器端:
post("/images"){
contentType = "image/jpeg" //for displaying the image
val imInBytes = params("image") //obtain data from request body
//do something with it.
}
任何帮助将不胜感激!