🐛 修复本地存储 BUG

This commit is contained in:
zhaojun1998
2019-12-03 22:42:38 +08:00
parent bf02366cf6
commit 9ef217c33c
3 changed files with 8 additions and 11 deletions

View File

@@ -48,6 +48,9 @@ public class SystemConfigService {
case SystemConfigConstant.PASSWORD:
systemConfigDTO.setPassword(systemConfig.getValue());
break;
case SystemConfigConstant.DOMAIN:
systemConfigDTO.setDomain(systemConfig.getValue());
break;
default:break;
}
}

View File

@@ -17,7 +17,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Date;
@Controller
@@ -39,18 +38,13 @@ public class LocalController {
}
private ResponseEntity<FileSystemResource> export(File file) throws IOException {
// 获取文件 MIME 类型
String fileMimeType = Files.probeContentType(file.toPath());
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
HttpHeaders headers = new HttpHeaders();
if (fileMimeType == null || "".equals(fileMimeType)) {
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + file.getName());
} else {
mediaType = MediaType.parseMediaType(fileMimeType);
}
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName()));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Last-Modified", new Date().toString());

View File

@@ -84,7 +84,7 @@ public class LocalServiceImpl implements FileService {
@Override
public String getDownloadUrl(String path) throws Exception {
SystemConfig usernameConfig = systemConfigRepository.findByKey(SystemConfigConstant.DOMAIN);
return StringUtils.concatPath( usernameConfig.getValue(), "file" + path);
return StringUtils.removeDuplicateSeparator(usernameConfig.getValue() + "/file/" + path);
}
public String getFilePath() {