nacos配置文件户及数据库文件
This commit is contained in:
parent
b3afa3cfd7
commit
8e423b0744
|
|
@ -4,6 +4,7 @@ package com.bonus.file.controller;
|
|||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.utils.BASE64DecodedMultipartFile;
|
||||
import com.bonus.common.entity.file.FileExportVo;
|
||||
import com.bonus.common.security.annotation.InnerAuth;
|
||||
import com.bonus.file.mongodb.service.FileUploadService;
|
||||
import com.bonus.file.mongodb.util.MongodbFileUtil;
|
||||
import com.bonus.system.api.domain.SysFile;
|
||||
|
|
@ -78,6 +79,7 @@ public class MongoFileUploadController {
|
|||
|
||||
@ApiOperation(value = "单文件上传")
|
||||
@PostMapping("singleUploadFile")
|
||||
@InnerAuth
|
||||
public R singleUploadFile(@RequestParam(value = "file", required = false) MultipartFile file){
|
||||
try {
|
||||
FileExportVo fileExportVo = mongoService.uploadFile(file);
|
||||
|
|
@ -90,6 +92,7 @@ public class MongoFileUploadController {
|
|||
|
||||
@ApiOperation(value = "多文件上传")
|
||||
@PostMapping("mostUploadFile")
|
||||
@InnerAuth
|
||||
public R mostUploadFile(@RequestParam(value = "files", required = false) MultipartFile[] files){
|
||||
try {
|
||||
List<MultipartFile> multipartFiles = Arrays.asList(files);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.springframework.data.mongodb.gridfs.GridFsTemplate;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
|
@ -157,8 +158,8 @@ public class FileMongoServiceImpl implements FileUploadService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public FileExportVo saveBinaryFile(MultipartFile file) throws Exception {
|
||||
|
||||
String suffix = getFileSuffix(file);
|
||||
InputStream inputStream= file.getInputStream();
|
||||
MongoFile mongoFile = mongoFileRepository.save(
|
||||
MongoFile.builder()
|
||||
.fileName(file.getOriginalFilename())
|
||||
|
|
@ -167,10 +168,10 @@ public class FileMongoServiceImpl implements FileUploadService {
|
|||
.contentType(file.getContentType())
|
||||
.uploadDate(DateTimeHelper.getNowTime())
|
||||
.suffix(suffix)
|
||||
.md5(Md5Util.getMd5(file.getInputStream()))
|
||||
.md5(Md5Util.getMd5(inputStream))
|
||||
.build()
|
||||
);
|
||||
|
||||
inputStream.close();
|
||||
return new FileExportVo(mongoFile);
|
||||
}
|
||||
|
||||
|
|
@ -183,9 +184,8 @@ public class FileMongoServiceImpl implements FileUploadService {
|
|||
*/
|
||||
public FileExportVo saveGridFsFile(MultipartFile file) throws Exception {
|
||||
String suffix = getFileSuffix(file);
|
||||
|
||||
String gridFsId = this.storeFileToGridFs(file.getInputStream(), file.getContentType());
|
||||
|
||||
InputStream inputStream= file.getInputStream();
|
||||
String gridFsId = this.storeFileToGridFs(inputStream, file.getContentType());
|
||||
MongoFile mongoFile = mongoTemplate.save(
|
||||
MongoFile.builder()
|
||||
.fileName(file.getOriginalFilename())
|
||||
|
|
@ -193,11 +193,11 @@ public class FileMongoServiceImpl implements FileUploadService {
|
|||
.contentType(file.getContentType())
|
||||
.uploadDate(DateTimeHelper.getNowTime())
|
||||
.suffix(suffix)
|
||||
.md5(Md5Util.getMd5(file.getInputStream()))
|
||||
.md5(Md5Util.getMd5(inputStream))
|
||||
.gridFsId(gridFsId)
|
||||
.build()
|
||||
);
|
||||
|
||||
inputStream.close();
|
||||
return new FileExportVo(mongoFile);
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +244,9 @@ public class FileMongoServiceImpl implements FileUploadService {
|
|||
// TODO 获取流对象
|
||||
GridFsResource resource = new GridFsResource(fsFile, in);
|
||||
// TODO 获取数据
|
||||
mongoFile.setContent(new Binary(IoUtil.readBytes(resource.getInputStream())));
|
||||
InputStream inputStream= resource.getInputStream();
|
||||
mongoFile.setContent(new Binary(IoUtil.readBytes(inputStream)));
|
||||
inputStream.close();
|
||||
return Optional.of(mongoFile);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,13 @@ server:
|
|||
port: 19300
|
||||
|
||||
# Spring
|
||||
spring:
|
||||
spring:
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 100MB
|
||||
location: D:\File
|
||||
|
||||
application:
|
||||
# 应用名称
|
||||
name: bonus-file
|
||||
|
|
@ -13,7 +19,7 @@ spring:
|
|||
cloud:
|
||||
nacos:
|
||||
username: nacos
|
||||
password: nacos
|
||||
password: ENC(b8K5x5rjN7qdGdmhgzFayK/P6ZVbC/UNBHjx2SBJkoqU149aXRtJsFhDZcgpckFf)
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 127.0.0.1:8848
|
||||
|
|
@ -38,3 +44,8 @@ spring:
|
|||
#文件存储类型 默认 本地存储 oss 时是oss存储 mongodb 、obs 进行区分存储
|
||||
file:
|
||||
save-type: oss
|
||||
|
||||
#加密组件
|
||||
jasypt:
|
||||
encryptor:
|
||||
password: Encrypt
|
||||
Loading…
Reference in New Issue