如何上传具有相同参数名称的多个文件

时间:2019-01-25 12:56:54

标签: spring rest unit-testing spring-boot spring-cloud

我正在寻找一种为以下其余服务创建Spring Cloud Contract的解决方案,它允许上传具有相同参数名称的多个文件:

    @PostMapping(value = "/uploadFiles")
    public ResponseEntity uploadFiles(@RequestParam("files") MultipartFile[] files) {
        // some code...
    }

我尝试了以下解决方案,但不起作用

org.springframework.cloud.contract.spec.Contract.make {
    request {
        method 'POST'
        url $(c('/uploadFiles'))
        headers {
            header 'Content-Type': $(c(regex('application/json.*')), p('application/json;charset=UTF-8'))
        }
        multipart(
            files: [
                named(
                    name: $(c(regex(nonEmpty())), p('file1.bin')),
                    content: $(c(regex(nonEmpty())), p('BINARY DATA')),
                    contentType: $(c(regex(nonEmpty())), p('application/octet-stream')),
                ),
                named(
                    name: $(c(regex(nonEmpty())), p('file2.bin')),
                    content: $(c(regex(nonEmpty())), p('BINARY DATA')),
                    contentType: $(c(regex(nonEmpty())), p('application/octet-stream')),
                )
            ]
        )
    }
    response {
        status OK()
    }
}

我认为Spring Cloud Contract不允许发送具有相同请求参数名称的多个值!你觉得呢?

0 个答案:

没有答案
相关问题