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.
This commit is contained in:
Mark Paluch
2018-07-06 13:01:09 +02:00
parent 1a3b9e3c42
commit 6f011b0fa1

View File

@@ -51,6 +51,7 @@ import com.mongodb.client.gridfs.model.GridFSUploadOptions;
* @author Martin Baumgartner
* @author Christoph Strobl
* @author Mark Paluch
* @author Niklas Helge Hanft
*/
public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver {
@@ -228,7 +229,7 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
public GridFsResource getResource(String location) {
GridFSFile file = findOne(query(whereFilename().is(location)));
return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(location)) : null;
return file != null ? new GridFsResource(file, getGridFs().openDownloadStream(file.getObjectId())) : null;
}
/*
@@ -246,13 +247,13 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
if (path.isPattern()) {
GridFSFindIterable files = find(query(whereFilename().regex(path.toRegex())));
List<GridFsResource> resources = new ArrayList<GridFsResource>();
List<GridFsResource> resources = new ArrayList<>();
for (GridFSFile file : files) {
resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getFilename())));
resources.add(new GridFsResource(file, getGridFs().openDownloadStream(file.getObjectId())));
}
return resources.toArray(new GridFsResource[resources.size()]);
return resources.toArray(new GridFsResource[0]);
}
return new GridFsResource[] { getResource(locationPattern) };