我想我正在将图像正确保存到Postgres,但是尝试加载图像会得到意想不到的结果.我真的不知道错误是在保存还是加载.
这是我保存图像的Anorm代码:
def storeBadgeImage(badgeHandle: String, imgFile: File) = {
val cmd = """
|update badge
|set img={imgBytes}
|where handle = {badgeHandle}
"""
var fis = new FileInputStream(imgFile)
var imgBytes: Array[Byte] = Resource.fromInputStream(fis).byteArray
// at this point I see the image in my browser if I return the imgBytes in the HTTP response, so I'm good so far.
DB.withConnection { implicit c =>
{
try {
SQL(cmd stripMargin).on("badgeHandle" -> badgeHandle, "imgBytes" -> imgBytes).executeUpdate() match {
case 0 => "update failed for …Run Code Online (Sandbox Code Playgroud) 我喜欢配置"代码作为数据"的想法,因为从案例类获得的验证与配置文件所需的验证相同.Twitter写了一个很好的Eval实用程序,使这很容易(https://github.com/twitter/util).我想允许用户将配置文件上传到远程服务.这开辟了为我的远程服务注入代码的潜力.
例如,如果我有以下配置案例类:
case class MyConfig(param1: String)
Run Code Online (Sandbox Code Playgroud)
我希望用户能够上传包含命令的文件:
MyConfig(param1 = "My Param Value")
Run Code Online (Sandbox Code Playgroud)
...但不是包含命令的文件:
MyConfig(param1 = {import someDangerousPackage; someDangerousCommand(); "My Param Value"})
Run Code Online (Sandbox Code Playgroud)
有没有办法拦截编译,以确保没有调用任何函数?
我的play框架应用程序是scala(而不是Java).我找到了一个页面,描述了如何使用实用程序类play.test.Helpers进行单元测试路由.这个例子是Java,而不是scala.我在scala中编写了测试,但是我收到错误"消息:这不是JavaAction,不能以这种方式调用".
这是我发现的页面,描述了如何在play framework 2.0中测试路由:http: //digitalsanctum.com/2012/05/28/play-framework-2-tutorial-testing/
...这是我试图编写的代码来测试我的应用程序:
package conf
import org.scalatest._
import play.mvc.Result
import play.test.Helpers._
class routeTest extends FunSpec with ShouldMatchers {
describe("route tests") {
it("") {
// routeAndCall() fails. Message: This is not a JavaAction and can't be invoked this way.
val result = routeAndCall(fakeRequest(GET, "/"))
result should not be (null)
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是因为我的行为是Scala而不是Java?我可以通过Scala控制器对我的路线进行单元测试吗