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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.0.0
    • Fix Version/s: 3.0.2
    • Component/s: GridFS
    • Labels:
    • Environment:
      Tested in Windows 7, Java SE 1.8 but appñlies for all
    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Java Sprint 19

      Description

      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

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: