|
@@ -112,7 +112,7 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
* @return 下载流
|
|
|
*/
|
|
|
@Override
|
|
|
- public ResponseEntity<Object> download(String fileId,boolean isDown) {
|
|
|
+ public ResponseEntity<Object> download(String fileId, boolean isDown) {
|
|
|
DocumentVO vo = downloadFile(fileId);
|
|
|
if (Objects.nonNull(vo)) {
|
|
|
String disposition = isDown ? "attachment" : "inline";
|
|
@@ -181,9 +181,8 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
*/
|
|
|
public DocumentVO saveBinaryFile(MultipartFile file) throws Exception {
|
|
|
String suffix = getFileSuffix(file);
|
|
|
- DocumentFile documentFile = null;
|
|
|
try (InputStream in = file.getInputStream()) {
|
|
|
- documentFile = mongoFileRepository.save(
|
|
|
+ DocumentFile documentFile = mongoFileRepository.save(
|
|
|
DocumentFile.builder()
|
|
|
.fileName(file.getOriginalFilename())
|
|
|
.fileSize(file.getSize())
|
|
@@ -194,13 +193,13 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
.md5(Md5Utils.getMd5ByInputStream(in))
|
|
|
.build()
|
|
|
);
|
|
|
+ return new DocumentVO(documentFile);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw e;
|
|
|
// 抛出异常,让调用方处理
|
|
|
}
|
|
|
|
|
|
- return new DocumentVO(documentFile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -212,10 +211,9 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
*/
|
|
|
public DocumentVO saveGridFsFile(MultipartFile file) throws Exception {
|
|
|
String suffix = getFileSuffix(file);
|
|
|
- DocumentFile documentFile = null;
|
|
|
try (InputStream in = file.getInputStream()) {
|
|
|
String gridFsId = this.storeFileToGridFS(in, file.getOriginalFilename(), file.getContentType());
|
|
|
- documentFile = mongoFileRepository.save(
|
|
|
+ DocumentFile documentFile = mongoFileRepository.save(
|
|
|
DocumentFile.builder()
|
|
|
.fileName(file.getOriginalFilename())
|
|
|
.fileSize(file.getSize())
|
|
@@ -226,14 +224,12 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
.gridFsId(gridFsId)
|
|
|
.build()
|
|
|
);
|
|
|
+ return new DocumentVO(documentFile);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
throw e;
|
|
|
// 抛出异常,让调用方处理
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- return new DocumentVO(documentFile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -260,6 +256,20 @@ public class MongoServiceImpl implements IMongoService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 查询并复制mongo文件
|
|
|
+ *
|
|
|
+ * @param id 文件id
|
|
|
+ * @return 对象
|
|
|
+ */
|
|
|
+ public DocumentVO copy(String id) {
|
|
|
+ Optional<DocumentFile> optional = mongoFileRepository.findById(id);
|
|
|
+ DocumentFile file = optional.get();
|
|
|
+ file.setId(null);
|
|
|
+ mongoFileRepository.save(file);
|
|
|
+ return new DocumentVO(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取Grid文件
|
|
|
*
|
|
|
* @param id
|