0

是否可以Http.outboundGateway为多部分提供字节数组而不是文件?REST 模板支持此实现(请参阅:https ://medium.com/@voziv/posting-a-byte-array-instead-of-a-file-using-spring-s-resttemplate-56268b45140b )。

当我使用上面的代码片段时,我得到: Caused by: java.lang.IllegalArgumentException: Message payload must be of type [java.io.File]: java.lang.String

片段:

.transform(m -> {
    MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
    ByteArrayResource contentsAsResource = new ByteArrayResource((byte[]) m) {
        @Override
        public String getFilename() {
            return "temp";
        }
    };
    body.add("document", contentsAsResource);
    return body;
})
.handle(Http.outboundGateway(uri)
    .httpMethod(HttpMethod.POST)
    .expectedResponseType(String.class), this.advices.spec())
4

0 回答 0