Skip to content

Commit 6f011b0

Browse files
committed
DATAMONGO-2021 - Polishing.
Adapt getResources(…) to use the file id and no longer the file name when opening a download stream. Add author tag. Original pull request: #581.
1 parent 1a3b9e3 commit 6f011b0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* @author Martin Baumgartner
5252
* @author Christoph Strobl
5353
* @author Mark Paluch
54+
* @author Niklas Helge Hanft
5455
*/
5556
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
5657

@@ -228,7 +229,7 @@ public ClassLoader getClassLoader() {
228229
public GridFsResource getResource(String location) {
229230

230231
GridFSFile file = findOne(query(whereFilename().is(location)));
231-
return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(location)) : null;
232+
return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(file.getObjectId())) : null;
232233
}
233234

234235
/*
@@ -246,13 +247,13 @@ public GridFsResource[] getResources(String locationPattern) {
246247
if (path.isPattern()) {
247248

248249
GridFSFindIterable files = find(query(whereFilename().regex(path.toRegex())));
249-
List<GridFsResource> resources = new ArrayList<GridFsResource>();
250+
List<GridFsResource> resources = new ArrayList<>();
250251

251252
for (GridFSFile file : files) {
252-
resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getFilename())));
253+
resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getObjectId())));
253254
}
254255

255-
return resources.toArray(new GridFsResource[resources.size()]);
256+
return resources.toArray(new GridFsResource[0]);
256257
}
257258

258259
return new GridFsResource[] { getResource(locationPattern) };

0 commit comments

Comments
 (0)