前端传过来的base64大小超过后端能解析的最大值
来源:9-3 分片上传功能开发2

慕运维6519169
2023-07-18
前端传到后端的base64字符串太大,超出了JSON的最大值,要怎么规避这个问题?前端已经配置成10M一个shard了。
后端log:
38.284 WARN o.s.w.s.m.s.DefaultHandlerExceptionResolver:207 Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
30.953 WARN o.s.w.s.m.s.DefaultHandlerExceptionResolver:207 Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
41.037 INFO c.n.d.s.r.a.ConfigClusterResolver:43 Resolving eureka endpoints via configuration
41.041 INFO c.n.d.s.r.a.ConfigClusterResolver:43 Resolving eureka endpoints via configuration
14.965 WARN o.s.w.s.m.s.DefaultHandlerExceptionResolver:207 Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: String length (5043368) exceeds the maximum length (5000000)]
41.042 INFO c.n.d.s.r.a.ConfigClusterResolver:43 Resolving eureka endpoints via configuration
写回答
2回答
-
慕运维6519169
提问者
2023-07-20
问题已解决。com.fasterxml.jackson版本引起。学习的时候已经是2023年7月,前端后端所依赖的版本已经和开课的时候差别很大。为了更加贴近项目需求,后端微服务采用的是spring boot 3.1.0版本,其依赖的fasterxml.jackson是2.15.0。自2.15.0起,Jackson对字符串大小作出限制,不能超过5M,具体参见:https://github.com/FasterXML/jackson-core/issues/1001。
目前绕过的办法是在Application内增加对Jackson的bean的配置。下面配置允许最大的字符串长度是100M。
// FileApplication.java //jackson2.15 bug @Bean Jackson2ObjectMapperBuilderCustomizer customStreamReadConstraints() { return (builder) -> builder.postConfigurer((objectMapper) -> objectMapper.getFactory() .setStreamReadConstraints(StreamReadConstraints.builder().maxNestingDepth(2000).maxStringLength(100_000_000).build())); }
212023-07-21 -
慕运维6519169
提问者
2023-07-18
前端的分片已经切割为10M每片。
022023-07-20
相似问题