Boot版本,使用OpenFeign,无法上传文件!

Blade 未结 1 130
178389386
178389386 剑童 2025-02-06 17:50

一、该问题的重现步骤是什么?

1. Boot版本:4.1.0

2. image.png

image.png

image.png

3.


二、你期待的结果是什么?实际看到的又是什么?


希望FeignClient可以正常的上传文件,目前调用接口不上传文件基本没有问题;但是一上传文件就出现400错误;当前项目需要用这个接口上传文件,死活无法成功!


image.png

image.png


三、你正在使用的是什么产品,什么版本?在什么操作系统上?


Boot,版本4.1.0 ,本地开发,需要给其他系统上传图片


四、请提供详细的错误堆栈信息,这很重要。


feign.FeignException$BadRequest: [400] during [POST] to [http://127.0.0.1:9212/user/profile/avatar] [ShopeeShopMediaClientApi#apiV2MediaSpaceUploadImage(MultipartFile)]: [<!doctype html><html><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;... (435 bytes)]

at feign.FeignException.clientErrorStatus(FeignException.java:222)

at feign.FeignException.errorStatus(FeignException.java:203)

at feign.FeignException.errorStatus(FeignException.java:194)

at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:103)

at feign.InvocationContext.decodeError(InvocationContext.java:126)

at feign.InvocationContext.proceed(InvocationContext.java:72)

at feign.ResponseHandler.handleResponse(ResponseHandler.java:63)

at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:114)

at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70)

at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:99)

at org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory$1.proceed(FeignCachingInvocationHandlerFactory.java:66)

at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:64)

at org.springframework.cache.interceptor.CacheAspectSupport.invokeOperation(CacheAspectSupport.java:416)

at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:401)

at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:74)

at org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory.lambda$create$1(FeignCachingInvocationHandlerFactory.java:53)

at jdk.proxy2/jdk.proxy2.$Proxy165.apiV2MediaSpaceUploadImage(Unknown Source)

at org.springblade.AppRunner.run(AppRunner.java:124)

at org.springframework.boot.SpringApplication.lambda$callRunner$4(SpringApplication.java:786)

at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83)

at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60)

at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88)

at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798)

at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786)

at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774)

at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)

at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)

at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)

at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)

at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)

at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)

at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)

at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)

at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:342)

at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)

at org.springblade.core.launch.BladeApplication.run(BladeApplication.java:59)

at org.springblade.Application.main(Application.java:50)


五、若有更多详细信息,请在下面提供。


1条回答
  • 2025-02-06 17:51

    boot版本没有对feign做过适配,你就用HttpUtil这类工具调用接口。或者直接引入OssTemplate来进行文件上传功能的实现。

    作者追问:2025-02-06 18:02

    现有项目在FeignClient中封装了大量内容;能否告知,为何使用Feign上传文件,始终出现400的原因,受限项目,尽量还是要在Feign中上传文件

    0 讨论(0)
代码语言
提交回复