本地文件上传修改
This commit is contained in:
@@ -4,6 +4,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.vetti.common.core.domain.R;
|
||||||
|
import com.vetti.common.core.domain.dto.FileDto;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -25,6 +30,7 @@ import com.vetti.framework.config.ServerConfig;
|
|||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
@Api(tags ="通用请求处理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/common")
|
@RequestMapping("/common")
|
||||||
public class CommonController
|
public class CommonController
|
||||||
@@ -42,6 +48,7 @@ public class CommonController
|
|||||||
* @param fileName 文件名称
|
* @param fileName 文件名称
|
||||||
* @param delete 是否删除
|
* @param delete 是否删除
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("通用下载请求")
|
||||||
@GetMapping("/download")
|
@GetMapping("/download")
|
||||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
||||||
{
|
{
|
||||||
@@ -71,8 +78,9 @@ public class CommonController
|
|||||||
/**
|
/**
|
||||||
* 通用上传请求(单个)
|
* 通用上传请求(单个)
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("通用上传请求(单个)")
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public AjaxResult uploadFile(MultipartFile file) throws Exception
|
public R<FileDto> uploadFile(MultipartFile file) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -81,24 +89,25 @@ public class CommonController
|
|||||||
// 上传并返回新文件名称
|
// 上传并返回新文件名称
|
||||||
String fileName = FileUploadUtils.upload(filePath, file);
|
String fileName = FileUploadUtils.upload(filePath, file);
|
||||||
String url = serverConfig.getUrl() + fileName;
|
String url = serverConfig.getUrl() + fileName;
|
||||||
AjaxResult ajax = AjaxResult.success();
|
FileDto fileDto = new FileDto();
|
||||||
ajax.put("url", url);
|
fileDto.setUrl(url);
|
||||||
ajax.put("fileName", fileName);
|
fileDto.setFileName(fileName);
|
||||||
ajax.put("newFileName", FileUtils.getName(fileName));
|
fileDto.setNewFileName(FileUtils.getName(fileName));
|
||||||
ajax.put("originalFilename", file.getOriginalFilename());
|
fileDto.setOriginalFilename(file.getOriginalFilename());
|
||||||
return ajax;
|
return R.ok(fileDto);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return AjaxResult.error(e.getMessage());
|
return R.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用上传请求(多个)
|
* 通用上传请求(多个)
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("通用上传请求(多个)")
|
||||||
@PostMapping("/uploads")
|
@PostMapping("/uploads")
|
||||||
public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
|
public R<FileDto> uploadFiles(List<MultipartFile> files) throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -118,16 +127,17 @@ public class CommonController
|
|||||||
newFileNames.add(FileUtils.getName(fileName));
|
newFileNames.add(FileUtils.getName(fileName));
|
||||||
originalFilenames.add(file.getOriginalFilename());
|
originalFilenames.add(file.getOriginalFilename());
|
||||||
}
|
}
|
||||||
AjaxResult ajax = AjaxResult.success();
|
FileDto fileDto = new FileDto();
|
||||||
ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
|
fileDto.setUrl(StringUtils.join(urls, FILE_DELIMETER));
|
||||||
ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
|
fileDto.setFileName(StringUtils.join(fileNames, FILE_DELIMETER));
|
||||||
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
fileDto.setNewFileName(StringUtils.join(newFileNames, FILE_DELIMETER));
|
||||||
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
fileDto.setOriginalFilename(StringUtils.join(originalFilenames, FILE_DELIMETER));
|
||||||
return ajax;
|
|
||||||
|
return R.ok(fileDto);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return AjaxResult.error(e.getMessage());
|
return R.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.vetti.common.core.domain.dto;
|
||||||
|
|
||||||
|
import com.vetti.common.utils.file.FileUtils;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传文件返回结构对象
|
||||||
|
*
|
||||||
|
* @author wangxiangshun
|
||||||
|
* @date 2025-10-29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class FileDto {
|
||||||
|
|
||||||
|
@ApiModelProperty("文件地址")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@ApiModelProperty("文件名")
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
@ApiModelProperty("新文件名")
|
||||||
|
private String newFileName;
|
||||||
|
|
||||||
|
@ApiModelProperty("原始文件名")
|
||||||
|
private String originalFilename;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user