[JAVA-4230] GridFSDownloadStream couldn't read all data to byte array Created: 14/Jul/21  Updated: 04/May/22  Resolved: 15/Jul/21

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Hoang Nguyenv Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

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

 



 Comments   
Comment by Jeffrey Yemin [ 14/Jul/21 ]

Hi there, thank you for reaching out. As this sounds like a support issue, I wanted to give you some resources to get this question answered more quickly:

  • Our MongoDB support portal, located at support.mongodb.com
  • Our MongoDB community portal, located here
  • If you are an Atlas customer, you can review your support options by clicking Support in the top menu bar of the Atlas UI

Just in case you have already opened a support case and are not receiving sufficient help, please let me know and I can facilitate escalating your issue.

Thank you!

Generated at Thu Feb 08 09:01:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.