更新原文件上传时间
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
Some checks are pending
Java CI with Maven / build (11) (push) Waiting to run
Java CI with Maven / build (17) (push) Waiting to run
Java CI with Maven / build (8) (push) Waiting to run
yudao-ui-admin CI / build (14.x) (push) Waiting to run
yudao-ui-admin CI / build (16.x) (push) Waiting to run
This commit is contained in:
parent
60cf192b9b
commit
33542df0eb
@ -67,12 +67,13 @@ public class FileController {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/{configId}/get/**")
|
||||
@GetMapping("/{configId}/get/{fileDate}/**")
|
||||
@PermitAll
|
||||
@Operation(summary = "下载文件")
|
||||
@Parameter(name = "configId", description = "配置编号", required = true)
|
||||
public void getFileContent(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
@PathVariable("fileDate") String fileDate,//获取时间信息
|
||||
@PathVariable("configId") Long configId) throws Exception {
|
||||
// 获取请求的路径
|
||||
String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false);
|
||||
@ -82,8 +83,13 @@ public class FileController {
|
||||
// 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
||||
path = URLUtil.decode(path);
|
||||
|
||||
String[] parts = path.split("/");
|
||||
if (parts.length > 1) { path = parts[1]; }//分离原路径和时间信息
|
||||
|
||||
String filePath = fileDate+"\\"+path; //拼接原路径和时间信息
|
||||
|
||||
// 读取内容
|
||||
byte[] content = fileService.getFileContent(configId, path);
|
||||
byte[] content = fileService.getFileContent(configId, filePath);
|
||||
if (content == null) {
|
||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||
response.setStatus(HttpStatus.NOT_FOUND.value());
|
||||
|
@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 本地文件客户端
|
||||
@ -26,11 +28,17 @@ public class LocalFileClient extends AbstractFileClient<LocalFileClientConfig> {
|
||||
|
||||
@Override
|
||||
public String upload(byte[] content, String path, String type) {
|
||||
//获取当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
String date = now.format(formatter);//当前时间获取
|
||||
String filesPath = date+"\\"+path;
|
||||
String urlPath = date+"/"+path;
|
||||
// 执行写入
|
||||
String filePath = getFilePath(path);
|
||||
String filePath = getFilePath(filesPath);
|
||||
FileUtil.writeBytes(content, filePath);
|
||||
// 拼接返回路径
|
||||
return super.formatFileUrl(config.getDomain(), path);
|
||||
return super.formatFileUrl(config.getDomain(), urlPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user