20 changed files with 294 additions and 79 deletions
@ -0,0 +1,60 @@
|
||||
package com.ruoyi.web.controller.workflow; |
||||
|
||||
import cn.hutool.core.util.ObjectUtil; |
||||
import com.ruoyi.common.core.controller.BaseController; |
||||
import com.ruoyi.common.core.domain.R; |
||||
import com.ruoyi.system.domain.vo.SysOssVo; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestPart; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project ruoyi-flowable-plus |
||||
* @description 流程文件Controller |
||||
* @date 2024-04-26 15:25:13 |
||||
*/ |
||||
@Slf4j |
||||
@RequiredArgsConstructor |
||||
@RestController |
||||
@RequestMapping("/workflow/file") |
||||
public class WfFileController extends BaseController { |
||||
|
||||
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
||||
public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) throws IOException { |
||||
//http://localhost:81/dev-api/workflow/file/upload
|
||||
if (ObjectUtil.isNull(file)) { |
||||
return R.fail("上传文件不能为空"); |
||||
} |
||||
//获取原始文件名
|
||||
String originalFilename = file.getOriginalFilename(); |
||||
//获取文件扩展名 123.2.1.jpg
|
||||
int index = originalFilename.lastIndexOf("."); //最后一个.的下标
|
||||
String extname = originalFilename.substring(index); |
||||
//构造唯一的文件名(不能重复) -- uuid(通用唯一识别码)040bf482-284b-40a6-bf61-15c811d1b0d0
|
||||
String newFilename = UUID.randomUUID().toString() + extname; |
||||
log.info("新的文件名:{}", newFilename); |
||||
|
||||
//将文件存储在服务器的磁盘目录中 D:\demo\files
|
||||
file.transferTo(new File("D:\\mh_code\\flowable\\image\\" |
||||
+ newFilename)); |
||||
Map<String, String> map = new HashMap<>(2); |
||||
map.put("url", "https://bx.mhito.net/images/"+newFilename); |
||||
map.put("fileName", originalFilename); |
||||
map.put("ossId", String.valueOf(UUID.randomUUID())); |
||||
return R.ok(map); |
||||
} |
||||
|
||||
} |
After Width: | Height: | Size: 106 KiB |
Loading…
Reference in new issue