0

Is it possible to provide a byte array instead of a File to the Http.outboundGateway for multi-part? This implementation is supported by the REST template (see: https://medium.com/@voziv/posting-a-byte-array-instead-of-a-file-using-spring-s-resttemplate-56268b45140b).

When I'm using the above snippet, I'm getting: Caused by: java.lang.IllegalArgumentException: Message payload must be of type [java.io.File]: java.lang.String

Snippet:

.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())
Blink
  • 1,408
  • 13
  • 21
  • May we see more stack trace for that error? It isn't clear right now what causes it. Thanks – Artem Bilan Sep 04 '19 at 13:15
  • I think Http.outboundGateway expects MultiValueMap with Files. If you change the above code for body to the following, it works: `body.add("document", new FileSystemResource((File)m ));` Is it clear now or should I still add stack trace? – Blink Sep 05 '19 at 13:28
  • As I said: stack trace into the studio, please. We can think about problems, when we figure out the point of the error. More over you don't show what is that ` for body to: `. This doesn't feel like a productive discussion... – Artem Bilan Sep 05 '19 at 13:31

0 Answers0