坏文件描述符在play框架中的异常

时间:2017-07-13 11:50:28

标签: javascript java jquery playframework valums-file-uploader

尝试将图像输入流复制到某个路径时出现此错误

如果图像尺寸小于7kb

,我没有收到任何错误

我使用fileuploader(http://valums-file-uploader.github.io/file-uploader/)作为上传图片的媒介

我的服务器端代码在play framework 1.3

Play框架中的Java代码

private static File makeFile() {

   File file = null;
   String UPLOAD_PATH = getUploadPath();
   Logger.log4j.info("starting the upload progress");
   if (request.isNew) {
       FileOutputStream moveTo = null;

       // Another way I used to grab the name of the file
       String filename = request.params.get("qqfile");
       Logger.info("Absolute on where to send %s", UPLOAD_PATH + File.separator);
       InputStream data = null;
       try {
           data = request.body;
           File up = new File(UPLOAD_PATH);
           if (!up.exists()) {
               Logger.log4j.info("making directory " + up.getAbsolutePath() + ", result is : "
                       + up.mkdir());
           }
           File inputDoc = new File(UPLOAD_PATH + File.separator + filename);
           moveTo = new FileOutputStream(inputDoc);
           Logger.log4j.info("copying file to local system");
           IOUtils.copy(data, moveTo);
           Logger.log4j.info("file copied to local system : " + inputDoc.getAbsolutePath());
           moveTo.close();
           file = inputDoc;
       } catch (Exception ex) {
           Logger.log4j.error(ex.getMessage(), ex);
       } finally {
           if (data != null) {
               Logger.log4j.info("closing data input stream");
               try {
                   data.close();
               } catch (Exception ex) {
                   Logger.log4j.error(ex.getMessage(), ex);
               }
           }
       }
   }
   return file;
}

我在IOUtils.copy(data,moveTo)上获得了Exception;

记录我正在

java.io.IOException: Bad file descriptor
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:198)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1262)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1236)
at controllers.AbstractUIController.makeFile(AbstractUIController.java:326)

0 个答案:

没有答案