首页>代码>SpringBoot集成Thumbnailator压缩图片>/springboot-thumbnailator/src/main/java/com/simon/springbootthumbnailator/controller/ImgZipController.java
package com.simon.springbootthumbnailator.controller;

import com.simon.springbootthumbnailator.util.ImageUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 图片上传处理类
 *
 * @author zlzhaoe
 */
@Controller
public class ImgZipController {

    @ApiOperation(value = "图片上传", notes = "多项目图片上传工具类", httpMethod = "POST")
    @RequestMapping(value = "/img_upload_compress")
    @ResponseBody
    public Map<String, Object> img_upload_compress(
            @ApiParam(name = "file", value = "文件(图片)", required = true) @RequestParam(value = "file") MultipartFile file,
            @ApiParam(name = "path", value = "项目名称") @RequestParam(value = "path", required = false) String path,
            @ApiParam(name = "scale", value = "图片压缩比例:0.0~1.0") @RequestParam(value = "scale", required = false) Double scale) throws IOException {
        Map<String, Object> result = new HashMap<>();
        String resultImagePath = ImageUtil.imgUploadCompress(file, path, scale);
        if (resultImagePath.equals("0")) {
            result.put("code", "0");
            result.put("msg", "上传失败,后端异常!");
        } else if (resultImagePath.equals("-1")) {
            result.put("code", "-1");
            result.put("msg", "非法图片格式!");
        } else {
            result.put("code", "1");
            result.put("msg", resultImagePath);
        }
        return result;
    }
}
最近下载更多
crosa_Don  LV18 2023年5月22日
最代码官方  LV167 2023年2月19日
最近浏览更多
woldxy  LV12 2023年9月27日
jerry9832 2023年7月12日
暂无贡献等级
1529860026  LV24 2023年6月1日
陆程江  LV2 2023年5月29日
crosa_Don  LV18 2023年5月22日
tmdgdx  LV9 2023年4月14日
bin2337  LV4 2023年3月30日
Yimi1919  LV3 2023年3月23日
包子爱吃肉  LV1 2023年3月18日
神龙摆尾无拘束  LV2 2023年3月17日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友