我需要同时传递文件(通过form-data
)和DTO。因此,我尝试执行以下操作:
@PostMapping
public Mono<Void> method(@RequestPart("files") Flux<FilePart> files,
Dto dto) {
return Mono.empty();
}
并通过每个Dto
字段的参数初始化dto
。
所以我收到以下错误:
org.springframework.core.codec.CodecException: Type definition error: [simple type, class org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader$SynchronossFilePart]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader$SynchronossFilePart and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.LinkedHashMap["errors"]->java.util.Collections$UnmodifiableList[0]->org.springframework.validation.FieldError["rejectedValue"])
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.springframework.http.codec.multipart.SynchronossPartHttpMessageReader$SynchronossFilePart and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.LinkedHashMap["errors"]->java.util.Collections$UnmodifiableList[0]->org.springframework.validation.FieldError["rejectedValue"])
如果我完全删除Dto
参数,则图像将正确加载。
向@RequestBody
参数添加Dto
注释会产生以下错误:
Content type 'multipart/form-data;charset=UTF-8;boundary=rh4lsv9DycBf8hpV2snhKfRjSrj1GvHzVy' not supported for bodyType=com.example.Dto
通过将Dto
传递为@RequestParam("dto") String dto
并手动解析JSON来完成此工作,但这并不是一个完美的解决方案。
所以您需要所谓的混合多部分