-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.4.0
-
Component/s: GridFS
-
None
When using the driver and gridfs I get an error `java.lang.IllegalArgumentException: filename can not be null`. The data does not have a filename attribute in the gridfs store.
The source code shows that we are asserting not null for the filename just like the error tells us:
https://github.com/mongodb/mongo-java-driver/blob/master/driver-core/src/main/com/mongodb/client/gridfs/model/GridFSFile.java#L81
So do we have to assert not null for filename? My files will never have a filename that matters/is worth my time to create a filename on the way into gridfs.
java.lang.IllegalArgumentException: filename can not be null
at com.mongodb.assertions.Assertions.notNull(Assertions.java:37) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.model.GridFSFile.<init>(GridFSFile.java:81) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.model.GridFSFile.<init>(GridFSFile.java:61) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSFindIterableImpl$1.apply(GridFSFindIterableImpl.java:143) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSFindIterableImpl$1.apply(GridFSFindIterableImpl.java:122) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.MongoMappingCursor.next(MongoMappingCursor.java:44) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.MappingIterable.first(MappingIterable.java:45) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSFindIterableImpl.first(GridFSFindIterableImpl.java:102) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSFindIterableImpl.first(GridFSFindIterableImpl.java:45) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSBucketImpl.findTheFileInfoAndOpenDownloadStream(GridFSBucketImpl.java:292) ~[mongo-java-driver-3.2.2.jar:na]
at com.mongodb.client.gridfs.GridFSBucketImpl.openDownloadStream(GridFSBucketImpl.java:161)
Code:
MongoClient mongoClient = new MongoClient("127.0.0.1", 27017); MongoDatabase mongoDatabase = mongoClient.getDatabase("db"); GridFSBucket gridFSBucket = GridFSBuckets.create(mongoDatabase); ObjectId fileId = new ObjectId(Id); GridFSDownloadStream downloadStream = gridFSBucket.openDownloadStream(fileId);