• Springcloud 学习笔记13-使用PostMan上传/下载文件,前后端联合测试


    1.使用postman上传文件(post方式)

    (1)将请求方式选择为post,填写接口地址

    (2)填写请求头

    key:Content-Type

    value:multipart/form-data

    (3)填写Body

    form-data中的 key 选择 file

    (4)最后,发送请求即可。

    (5)后端接收前端所发请求

    /**
     * 文件上传服务入口
     */
    @RestController
    @Slf4j
    @RequestMapping("/fileUpload")
    public class FileUploadController {
        @Autowired
        FileUAProperties fileUAProperties;
    
        @Autowired
        IPmSubsysContentService pmSubsysContentService;
    
        @Autowired
        IPmSubsysInfoService pmSubsysInfoService;
    
        @Autowired
        private FileHandlerService fileHandlerService;
    
        @PostMapping(value = "/upload",consumes=MediaType.MULTIPART_FORM_DATA_VALUE)
        public Result<FlepResultDto> uploadFile(@RequestParam String fileInfo,
                @RequestPart(value = "file") MultipartFile file) throws IOException {
            String md5=DigestUtils.md5Hex(file.getInputStream());
            System.out.println(fileInfo);
            System.out.println(md5);
            return null;
        }
    }

    执行结果:

    2.使用postman下载文件(get方式)

    (1)将请求方式选择为get,填写接口地址

    (2)填写params

    (3)最后,发送请求即可。

    (4)后端代码

    @GetMapping("/download")
        public void downloadFile(@RequestParam String fileId, @RequestParam String subsysCode, @RequestParam String contentId, HttpServletResponse response){
            log.info("开始处理文件[{}]下载请求.....",fileId);
            log.info(subsysCode);
            log.info(contentId);
    }

    执行结果:

    3.使用postman查询文件存储信息(get方式:既用实体类接收多个参数也用RequestParam接收单个参数)

    (1)将请求方式选择为get,填写接口地址和参数

     (2)后端debug界面

    参考文献:

    https://blog.csdn.net/wsjzzcbq/article/details/82498583

  • 相关阅读:
    分糖果
    数字游戏
    错误票据
    包子凑数
    带分数
    翻硬币
    核桃的数量
    快速幂
    公倍数与素数筛选
    mysql 查询当天当周当月的数据
  • 原文地址:https://www.cnblogs.com/luckyplj/p/15222359.html
Copyright © 2020-2023  润新知