package com.evimage.modules.controller;
import com.evimage.modules.common.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.jar.JarException;
@Api(tags = "路径")
@RestController
@RequestMapping("/modules/path")
@Slf4j
public class PathController {
@Value("${file.path}")
private String filePath;
@ApiOperation(value = "文件上传", notes = "文件上传")
@PostMapping("/savaFiles")
public Result<String> savaFiles(MultipartFile[] files) {
List<MultipartFile> multipartFiles = Arrays.asList(files);
String path = filePath + System.currentTimeMillis();
for (MultipartFile file : multipartFiles) {
try {
File targetFile = new File(path, file.getOriginalFilename());
// 保存文件
file.transferTo(targetFile);
}catch (Exception e) {
return Result.error("文件上传失败!文件为:" + file.getOriginalFilename());
}
}
return Result.ok(path);
}
}
java多文件上传到固定目录下
最新推荐文章于 2024-11-12 21:14:07 发布