fangyuan
2022-11-21 5cba031b4fcc437568a46295739fda3dae7ae41f
ycl-platform/src/main/java/com/ycl/controller/ImageUploadController.java
@@ -21,12 +21,12 @@
@RequestMapping("upload")
@Api(tags = "图片上传")
public class ImageUploadController {
    @ApiOperation(value="上传图片")
    @ApiOperation(value="/image", notes = "上传图片")
    @RequestMapping(value = "/image", method = RequestMethod.POST)
    public CommonResult uploadImage(HttpServletRequest request, MultipartFile image) throws IOException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String filePath = "/images/" + sdf.format(new Date());
        String imageFolderPath = request.getServletContext().getRealPath(filePath);
        File imageFolder = new File(imageFolderPath);
@@ -42,6 +42,7 @@
                .append(request.getServerPort())
                .append(request.getContextPath())
                .append(filePath);
        String imageName = UUID.randomUUID() + "_" + image.getOriginalFilename().replaceAll(" ", "");
        try {
            IOUtils.write(image.getBytes(), new FileOutputStream(new File(imageFolder, imageName)));
@@ -50,6 +51,6 @@
        } catch (IOException e) {
            e.printStackTrace();
        }
        return CommonResult.failed("上传失败!");
        return CommonResult.failed( "上传失败!");
    }
}