/**
* Method to store a file within MongoDB's GridFS.
* @param inputStream containing the file to store.
* @param fileName the file name under which the file is to be saved.
* @param contentType a mime type describing the contents of the file.
* @return a GridFSDBFile object on which an InputStream can be opened.
*/
public FSFile store(InputStream inputStream, String fileName, String contentType) {
try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfig.class)) {
GridFsOperations gridOperations =
(GridFsOperations) ctx.getBean("gridFsTemplate");
GridFSFile file = gridOperations.store(inputStream, fileName, contentType);
return new FSFile((ObjectId) file.getId(), fileName, contentType, file.getLength());
}
}
FileStoreImpl.java 文件源码
java
阅读 20
收藏 0
点赞 0
评论 0
项目:kanbanboard
作者:
评论列表
文章目录