-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: GridFS
Hi guys,
We are facing an issue that happened several times a day. Our java driver version is 3.12.7 and Mongo DB version is 4.0. It usually occurred while we use GridFSDownloadStream to get file with mongo db.
protected byte[] getFile(ObjectId fileId)protected byte[] getFile(ObjectId fileId) { GridFSBucket gridFSBucket = GridFSBuckets.create(mongoClientProvider.getMongoClient().getDatabase(SettingUtils.getMongoDbName())); byte[] data; try (GridFSDownloadStream downloadStream = gridFSBucket.openDownloadStream(fileId)) { int fileLength = (int) downloadStream.getGridFSFile().getLength(); data = new byte[fileLength]; downloadStream.read(data); } catch (RuntimeException exception) { throw new IllegalStateException("Error while retrieving file", exception); } return data; }
we testing with mongo java version 3.12:
<dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.12.7</version> </dependency>
We converted it to base64 string
Base64.getEncoder().encodeToString(internalDocument.getData());
and saw that we have "AAAAAA"(x1000) as end of base64 string and then we couldn't open files.
we can reproduce this case by loading a file with size >= 5MB