Spring REST - Can a RestTemplate consume multipart/mixed?

后端 未结 2 1212
走了就别回头了
走了就别回头了 2021-01-02 22:11

I want to write a REST service which does responed with a zipFile and some json data, everything in one multipart/mixed request.

The server part works fine and i am

2条回答
  •  感情败类
    2021-01-02 22:55

    I had the same issue and I think I achieved what you wanted. You just have to override the canRead method of the form converter. With your example something like below should work.

    FormHttpMessageConverter formConverter = new FormHttpMessageConverter() {
        @Override
        public boolean canRead(Class clazz, MediaType mediaType) {
            if (clazz == MyMultiValueMap.class) {
                return true;
            }
            return super.canRead(clazz, mediaType);
        }
    };
    

    And add this converter to your rest template.

提交回复
热议问题