更新文件上传后的accessUrl

This commit is contained in:
mazhicheng 2020-06-29 20:05:53 +08:00
parent d39cb307a9
commit 80006c969e
1 changed files with 14 additions and 6 deletions

View File

@ -111,11 +111,11 @@ public abstract class BaseFileController extends BaseController {
String fileUid = S.newUuid(); String fileUid = S.newUuid();
String newFileName = fileUid + "." + ext; String newFileName = fileUid + "." + ext;
String storageFullPath = FileHelper.saveFile(file, newFileName); String storageFullPath = FileHelper.saveFile(file, newFileName);
UploadFile uploadFile = new UploadFile(); UploadFile uploadFile = new UploadFile();
uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext); uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext);
uploadFile.setRelObjType(entityClass.getSimpleName()).setStoragePath(storageFullPath); uploadFile.setRelObjType(entityClass.getSimpleName()).setStoragePath(storageFullPath);
String accessUrl = buildAccessUrl(newFileName);
uploadFile.setAccessUrl(accessUrl);
String description = getString("description"); String description = getString("description");
uploadFile.setDescription(description); uploadFile.setDescription(description);
// 返回uploadFile对象 // 返回uploadFile对象
@ -152,19 +152,18 @@ public abstract class BaseFileController extends BaseController {
/** /**
* 保存文件 * 保存文件
* @param uploadFileFormDTO * @param uploadFileFormDTO
* @param <T>
* @return * @return
* @throws Exception * @throws Exception
*/ */
protected <T> UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception{ protected UploadFile saveFile(UploadFileFormDTO uploadFileFormDTO) throws Exception{
// 文件后缀 // 文件后缀
String originFileName = uploadFileFormDTO.getFile().getOriginalFilename(); String originFileName = uploadFileFormDTO.getFile().getOriginalFilename();
String ext = FileHelper.getFileExtByName( uploadFileFormDTO.getFile().getOriginalFilename()); String ext = FileHelper.getFileExtByName( uploadFileFormDTO.getFile().getOriginalFilename());
// 先保存文件 // 先保存文件
String fileUid = S.newUuid(); String fileUid = S.newUuid();
String newFileName = fileUid + "." + ext; String newFileName = fileUid + "." + ext;
String storageFullPath = FileHelper.saveFile( uploadFileFormDTO.getFile(), newFileName); String storageFullPath = FileHelper.saveFile(uploadFileFormDTO.getFile(), newFileName);
String accessUrl = FileHelper.getRelativePath(newFileName); String accessUrl = buildAccessUrl(newFileName);
UploadFile uploadFile = new UploadFile(); UploadFile uploadFile = new UploadFile();
uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext); uploadFile.setUuid(fileUid).setFileName(originFileName).setFileType(ext);
uploadFile.setRelObjType(uploadFileFormDTO.getRelObjType()) uploadFile.setRelObjType(uploadFileFormDTO.getRelObjType())
@ -175,6 +174,15 @@ public abstract class BaseFileController extends BaseController {
return uploadFile; return uploadFile;
} }
/**
* 构建文件访问/下载的url
* @param newFileName
* @return
*/
protected String buildAccessUrl(String newFileName){
return "/uploadFile/download/" + newFileName;
}
/** /**
* 保存上传文件信息 * 保存上传文件信息
* @param uploadFile * @param uploadFile