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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: 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
    • None
    • Fully Compatible
    • None
    • None
    • None
    • None
    • None
    • None

      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 Lawley
              Reporter:
              Augusto Decoud
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: