Spring Boot 2.0.1发行版中的GridFSDBFile [英] GridFSDBFile in spring boot 2.0.1 release
本文介绍了Spring Boot 2.0.1发行版中的GridFSDBFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Spring Boot 1.5.7迁移到其最新版本的Realease 2.0.1.在旧版本中,我使用此语法来恢复文件.
I am trying to migrate spring boot 1.5.7 to its latest version realease 2.0.1. In the old version I used this syntax to recover a file.
GridFSDBFile gridFsdbFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(fileId)));
您知道在新版本中将如何进行吗?我需要
Do you know how it would be done in the new version? I need
file.setInputStream(gridFsdbFile.getInputStream());
ty!
推荐答案
GridFSFile gridFsdbFile = gridFsTemplate.findOne(new Query(Criteria.where("_id").is(id)));
GridFSDownloadStream gridFSDownloadStream = gridFSBucket.openDownloadStream(gridFsdbFile.getObjectId());
GridFsResource gridFsResource = new GridFsResource(gridFsdbFile,gridFSDownloadStream );
然后
file.setInputStream(gridFsResource.getInputStream());
您可以像这样在MongoConfiguration中定义gridFSBucket
You can define gridFSBucket in MongoConfiguration like this
@Bean public GridFSBucket getGridFSBuckets() {
MongoDatabase db = mongoDbFactory().getDb();
return GridFSBuckets.create(db);
}
这篇关于Spring Boot 2.0.1发行版中的GridFSDBFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文