• 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

  • 相关阅读:
    TFS 2012使用简介(一)
    Android手机应用程序开发环境配置(Eclipse+Java+ADT)
    关于 all-delete-orphan
    Rest中的XML与JSON的序列化与反序列化
    C#Base64编码
    Visual Studio 2013支持Xamarin的解决方案
    【转】[WCF REST] 帮助页面与自动消息格式(JSON/XML)选择
    【转】 MEF 和 MAF
    Enable tfs feature in sharepoint
    Using a local farm account for a SharePoint 2013 installation
  • 原文地址:https://www.cnblogs.com/luckyplj/p/15222359.html
Copyright © 2020-2023  润新知