在生产服务器上获取错误“无法读取输入文件”但不在本地获取

时间:2013-10-03 12:43:21

标签: java scala image-processing amazon-s3 javax.imageio

我使用请求正文中包含的文件对请求进行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存储桶中获取的。

我调试了这段代码,在生产环境中,当“读取”完成时,有一个文件可用。

为什么无法从生产环境中读取文件?

问候

1 个答案:

答案 0 :(得分:0)

一个建议是不要吞下原始异常和堆栈跟踪。 在catch块中使用构造函数new Exception(message, catchedException)