|
@@ -1,17 +1,15 @@
|
|
|
package com.enteprise.uploadfile.controller;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.enteprise.common.config.RuoYiConfig;
|
|
|
+import com.enteprise.framework.config.ServerConfig;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import com.enteprise.common.annotation.Log;
|
|
|
import com.enteprise.common.core.controller.BaseController;
|
|
|
import com.enteprise.common.core.domain.AjaxResult;
|
|
@@ -20,6 +18,7 @@ import com.enteprise.uploadfile.domain.Uploadfile;
|
|
|
import com.enteprise.uploadfile.service.IUploadfileService;
|
|
|
import com.enteprise.common.utils.poi.ExcelUtil;
|
|
|
import com.enteprise.common.core.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* uploadfileController
|
|
@@ -33,6 +32,8 @@ public class UploadfileController extends BaseController
|
|
|
{
|
|
|
@Autowired
|
|
|
private IUploadfileService uploadfileService;
|
|
|
+ @Autowired
|
|
|
+ private ServerConfig serverConfig;
|
|
|
|
|
|
/**
|
|
|
* 查询uploadfile列表
|
|
@@ -101,4 +102,37 @@ public class UploadfileController extends BaseController
|
|
|
{
|
|
|
return toAjax(uploadfileService.deleteUploadfileByIds(ids));
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/upload")
|
|
|
+ public AjaxResult uploadFile(@RequestParam("file") MultipartFile file) {
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ return AjaxResult.error("上传文件不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 生成文件名(保留原始名称)
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ String uploadPath = RuoYiConfig.getUploadPath();
|
|
|
+ // 创建存储目录
|
|
|
+ File destDir = new File(uploadPath);
|
|
|
+ if (!destDir.exists()) {
|
|
|
+ destDir.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存文件
|
|
|
+ File destFile = new File(destDir, originalFilename);
|
|
|
+ file.transferTo(destFile);
|
|
|
+
|
|
|
+ // 构建返回URL
|
|
|
+ String url = serverConfig.getUrl() + "/" + originalFilename;
|
|
|
+
|
|
|
+ return AjaxResult.success()
|
|
|
+ .put("url", url)
|
|
|
+ .put("fileName", uploadPath + "/" + originalFilename)
|
|
|
+ .put("newFileName", originalFilename)
|
|
|
+ .put("originalFilename", originalFilename);
|
|
|
+ } catch (IOException e) {
|
|
|
+ return AjaxResult.error("上传失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|