|
|
@ -4,6 +4,7 @@ import com.kiisoo.ic.common.BaseController;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
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.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
@ -19,6 +20,9 @@ import java.util.UUID;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
public class FileController extends BaseController {
|
|
|
|
public class FileController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${upload.path}")
|
|
|
|
|
|
|
|
private String uploadPath;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
|
|
@ApiOperation(value = "上传文件")
|
|
|
|
@PostMapping(value = "/upload")
|
|
|
|
@PostMapping(value = "/upload")
|
|
|
|
public Map<String, Object> upload(@RequestParam(value = "file", required = false) MultipartFile file) {
|
|
|
|
public Map<String, Object> upload(@RequestParam(value = "file", required = false) MultipartFile file) {
|
|
|
@ -27,11 +31,11 @@ public class FileController extends BaseController {
|
|
|
|
if (fileName == null) return fail();
|
|
|
|
if (fileName == null) return fail();
|
|
|
|
fileName = renameToUUID(fileName);
|
|
|
|
fileName = renameToUUID(fileName);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
File targetPath = new File("upload");
|
|
|
|
File targetPath = new File(uploadPath);
|
|
|
|
if (!targetPath.exists()) {
|
|
|
|
if (!targetPath.exists()) {
|
|
|
|
boolean state = targetPath.mkdirs();
|
|
|
|
boolean state = targetPath.mkdirs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FileOutputStream out = new FileOutputStream("upload/" + fileName);
|
|
|
|
FileOutputStream out = new FileOutputStream(uploadPath + fileName);
|
|
|
|
out.write(file.getBytes());
|
|
|
|
out.write(file.getBytes());
|
|
|
|
out.flush();
|
|
|
|
out.flush();
|
|
|
|
out.close();
|
|
|
|
out.close();
|
|
|
|