From e18f506eddb0963d9788df28aa2878297e884cb4 Mon Sep 17 00:00:00 2001 From: Niklas Helge Hanft Date: Fri, 6 Jul 2018 09:23:31 +0200 Subject: [PATCH] DATAMONGO-2021 - Use getObjectId() instead of getFilename() for opening the GridFS download stream. Using the file name leads to duplicate resource streams as file names are not unique therefore we're using the file's ObjectId to lookup the file content. Original pull request: #581. --- .../org/springframework/data/mongodb/gridfs/GridFsTemplate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java index 5aa30005a..e3fa48150 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java @@ -240,7 +240,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver Assert.notNull(file, "GridFSFile must not be null!"); - return new GridFsResource(file, getGridFs().openDownloadStream(file.getFilename())); + return new GridFsResource(file, getGridFs().openDownloadStream(file.getObjectId())); } /*