文件上传支持自定义存储表;将文件管理独立file_upload表,与sys分离。
This commit is contained in:
@@ -4,15 +4,15 @@
|
||||
*/
|
||||
package com.jeesite.modules.file.web;
|
||||
|
||||
import com.jeesite.common.codec.EncodeUtils;
|
||||
import com.jeesite.common.collect.MapUtils;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.lang.StringUtils;
|
||||
import com.jeesite.common.mapper.JsonMapper;
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import com.jeesite.modules.file.entity.FileUpload;
|
||||
import com.jeesite.modules.file.entity.FileUploadParams;
|
||||
import com.jeesite.modules.file.service.FileUploadService;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -20,11 +20,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -47,9 +43,9 @@ public class FileUploadController extends BaseController {
|
||||
@ResponseBody
|
||||
public Map<String, Object> params() {
|
||||
Map<String, Object> model = MapUtils.newHashMap();
|
||||
model.put("imageAllowSuffixes", Global.getConfig("file.imageAllowSuffixes", ".gif,.bmp,.jpeg,.jpg,.ico,.png,.tif,.tiff,"));
|
||||
model.put("mediaAllowSuffixes", Global.getConfig("file.mediaAllowSuffixes", ".flv,.swf,.mkv,webm,.mid,.mov,.mp3,.mp4,.m4v,.mpc,.mpeg,.mpg,.swf,.wav,.wma,.wmv,.avi,.rm,.rmi,.rmvb,.aiff,.asf,.ogg,.ogv,"));
|
||||
model.put("fileAllowSuffixes", Global.getConfig("file.fileAllowSuffixes", ".doc,.docx,.rtf,.xls,.xlsx,.csv,.ppt,.pptx,.pdf,.vsd,.txt,.md,.xml,.rar,.zip,.7z,.tar,.tgz,.jar,.gz,.gzip,.bz2,.cab,.iso,"));
|
||||
model.put("imageAllowSuffixes", Global.getConfig("file.imageAllowSuffixes", FileUploadParams.DEFAULT_IMAGE_ALLOW_SUFFIXES));
|
||||
model.put("mediaAllowSuffixes", Global.getConfig("file.mediaAllowSuffixes", FileUploadParams.DEFAULT_MEDIA_ALLOW_SUFFIXES));
|
||||
model.put("fileAllowSuffixes", Global.getConfig("file.fileAllowSuffixes", FileUploadParams.DEFAULT_FILE_ALLOW_SUFFIXES));
|
||||
model.put("chunked", Global.getConfig("file.chunked", "true"));
|
||||
model.put("chunkSize", Global.getConfigToInteger("file.chunkSize", "10*1024*1024"));
|
||||
model.put("threads", Global.getConfigToInteger("file.threads", "3"));
|
||||
@@ -63,64 +59,28 @@ public class FileUploadController extends BaseController {
|
||||
*/
|
||||
@RequestMapping(value = "upload")
|
||||
@ResponseBody
|
||||
public Map<String, Object> upload(FileUploadParams params) {
|
||||
return fileUploadService.uploadFile(params);
|
||||
public Map<String, Object> uploadFile(FileUploadParams params) {
|
||||
return fileUploadService.uploadFile(new FileUpload(), params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
@RequestMapping(value = "/download/{fileUploadId}")
|
||||
public String download(@PathVariable("fileUploadId") String fileUploadId, String preview, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
FileUpload fileUpload = fileUploadService.get(fileUploadId);
|
||||
if (fileUpload != null && fileUpload.getFileEntity() != null && fileUpload.getFileEntity().getFileMd5() != null) {
|
||||
// 如果是文件预览,则跳转到文件下载页面,并传输文件预览参数
|
||||
if (StringUtils.isNotBlank(preview)){
|
||||
fileUpload.setPreviewFileUrl(true);
|
||||
String url = fileUpload.getFileUrl();
|
||||
if (StringUtils.contains(url, "://")) {
|
||||
url = "/userfiles/?url=" + EncodeUtils.encodeUrl(url);
|
||||
url += "&uid=" + fileUploadId;
|
||||
}
|
||||
url += StringUtils.contains(url, "?") ? "&" : "?";
|
||||
url += "fileName=" + EncodeUtils.encodeUrl(fileUpload.getFileName());
|
||||
url += "&preview=" + EncodeUtils.encodeUrl(preview);
|
||||
return REDIRECT + url;
|
||||
}
|
||||
// 下载文件流或获取下载文件URL并跳转
|
||||
String url = fileUploadService.getFileUploadServiceExtend().downFile(fileUpload, request, response);
|
||||
if (!"404".equals(url)){
|
||||
if (StringUtils.isNotBlank(url)){
|
||||
return REDIRECT + url;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
request.setAttribute("responseStatus", 200);
|
||||
request.setAttribute("message", text("sys.file.downloadFileNotExist"));
|
||||
request.getRequestDispatcher("/error/404").forward(request, response);
|
||||
return null;
|
||||
public String downloadFile(@PathVariable("fileUploadId") String fileUploadId, String preview, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
FileUpload fileUpload = fileUploadService.getFile(new FileUpload(fileUploadId));
|
||||
return fileUploadService.downloadFile(fileUpload, preview, request, response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取业务附件列表数据
|
||||
* 获取文件列表
|
||||
* @param fileUpload bizKey 和 bizType 为必填参数
|
||||
* @param bizKeyIsLike 是否对 bizKey 使用 RightLike 右模糊查询
|
||||
*/
|
||||
@RequestMapping(value = "fileList")
|
||||
@ResponseBody
|
||||
public String fileList(FileUpload fileUpload, Boolean bizKeyIsLike) {
|
||||
if (StringUtils.isNotBlank(fileUpload.getBizKey())
|
||||
&& StringUtils.isNotBlank(fileUpload.getBizType())){
|
||||
if (bizKeyIsLike != null && bizKeyIsLike){
|
||||
fileUpload.setBizKey_rightLike(fileUpload.getBizKey());
|
||||
fileUpload.setBizKey(null);
|
||||
}
|
||||
List<FileUpload> list = fileUploadService.findList(fileUpload);
|
||||
if(list != null && !list.isEmpty()){
|
||||
return JsonMapper.toJson(list);
|
||||
}
|
||||
}
|
||||
return renderResult(Global.FALSE, "No files.");
|
||||
public String getFileList(FileUpload fileUpload, Boolean bizKeyIsLike) {
|
||||
return fileUploadService.getFileList(fileUpload, bizKeyIsLike);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,7 +37,7 @@ var p = {
|
||||
imageThumbName: imageThumbName!'', // 如果开启了图片缩略图,这里可以指定缩略图名称,例如:150x150.jpg v5.4.2
|
||||
|
||||
serviceUpload: serviceUpload!(ctxAdmin+'/file/upload'), // 上传文件后台服务 v4.1.5
|
||||
serviceDownload: serviceDownload!(ctxAdmin+'/file/download/'), // 下载文件后台服务 v4.1.5
|
||||
serviceDownload: serviceDownload!(ctxAdmin+'/file/download'), // 下载文件后台服务 v4.1.5
|
||||
serviceFileList: serviceFileList!(ctxAdmin+'/file/fileList'), // 查询文件后台服务 v4.1.5
|
||||
|
||||
extendParams: extendParams!'', // 提交的上传扩展参数,例如:n1:'v1',n2:'v2',后台接受:fileEntity.getFileUploadParams().getExtend() v4.1.3
|
||||
|
||||
Reference in New Issue
Block a user