Tinku
Tinku

Reputation: 21

Bad file descripter Exception in play framework

I am getting this error while trying to copy Image inputstream to a certain path

I am not getting any error if the image size is less than 7kb

I am using fileuploader (http://valums-file-uploader.github.io/file-uploader/) as a medium to upload my image

My server side code is in play framework 1.3

Java code in play framework

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;
}

I am getting Exception at IOUtils.copy(data, moveTo);

Log I am getting

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)

Upvotes: 0

Views: 113

Answers (0)

Related Questions