zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    PTA(Basic Level)1012.数字分类
    PTA(Basic Level)1011.A+B和C
    PTA(Basic Level)1008.数组元素循环右移问题
    PTA(Basic Level)1009.说反话
    PTA(Basic Level)1010.一元多项式求导
    Leetcode 38.报数 By Python
    Leetcode 35.搜索插入位置 By Python
    查看Linux的所有线程
    Linux内核模块编程——Hello World模块
    JSP内置对象总结
  • 原文地址:https://www.cnblogs.com/luckyplj/p/15222359.html
Copyright © 2011-2022 走看看