0

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

如果图像大小小于 7kb,我不会收到任何错误

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

我的服务器端代码正在播放框架 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); 处遇到异常

我得到的日志

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)
4

0 回答 0