我使用请求正文中包含的文件对请求进行POST。
在我的方法中,我检索此文件
if(request.body.file("imageFile").getOrElse(null) != null) {
request.body.file("imageFile").map{ case FilePart(key, name, contentType, content) =>
try{
val in:InputStream = new BufferedInputStream(new ByteArrayInputStream(content))
image = ImageIO.read(in)
} catch {
case e => Logger.debug(e.printStackTrace.toString); throw new Exception(e.getMessage)
}
}
}
如果请求正文中包含一个文件,它会尝试获取它,否则它只是尝试从S3获取文件。
else {
try{
val in:InputStream = new BufferedInputStream(new ByteArrayInputStream(S3Storage.retrieveS3File("facebook.jpg").content))
image = ImageIO.read(in)
} catch {
case e:IOException => Logger.debug("Failed to retrieve facebook image"); throw new IOException(e.getMessage)
}
当我在计算机上运行它时,所有这一切都正常,但是当我在亚马逊服务器上检查并测试它时,image = ImageIO.read(in)
给了我一个错误; Can't read input file!
。
对我来说,这没有任何意义,因为该文件位于请求正文中,或者是从S3存储桶中获取的。
我调试了这段代码,在生产环境中,当“读取”完成时,有一个文件可用。
为什么无法从生产环境中读取文件?
问候
答案 0 :(得分:0)
一个建议是不要吞下原始异常和堆栈跟踪。
在catch块中使用构造函数new Exception(message, catchedException)
。