Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1813

GridFSInputFile.save() error when using createFile(File f)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.2
    • Affects Version/s: 3.0.0
    • Component/s: GridFS
    • Environment:
      Tested in Windows 7, Java SE 1.8 but appñlies for all
    • Fully Compatible

      Problem introduced in driver version 3.0.1.
      Drivers used: mongo-driver-code-3.0.1, mongo-driver-3.0.1, bson-3.0.1
      Trying to save a file to a GridFS database give the following error: com.mongodb.MongoException: couldn't save chunks

      Caused by: java.io.IOException: Stream Closed

      Solution:
      Change function;

          public GridFSInputFile createFile(final File file) throws IOException {
              FileInputStream fileInputStream = new FileInputStream(file);
              try {
                  return createFile(new FileInputStream(file), file.getName(), true);
              } finally {
                 fileInputStream.close();
              }
          }
      

      for this one:

          public GridFSInputFile createFile(final File file) throws IOException {
                  return createFile(new FileInputStream(file), file.getName(), true);
          }
      

      as in older versions.

      Problem dissapears.

      I do not know the reason for the changes in the 3.0.1 version. I did some tests after the changes and it seems it do not affect the rest of the class.

      This is my first post. I'm new to MongoDb, so excuse me if I did something wrong in this post.

      Thanks,
      Augusto

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            adecoud Augusto Decoud
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: