Fail to upload File(java.io.File) with FormEncoder + JAXRXContract
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
I've try to use feign for uploading image file.
First, I followed the example provided on the github README file(https://github.com/OpenFeign/feign-form)
This code is working
Builder formBuilder = Feign.builder()
.encoder(new FormEncoder())
.decoder(new JacksonDecoder())
.options(options)
.logger(new Slf4jLogger())
.requestInterceptor(new FeignRequestInterceptor())
.logLevel(Level.HEADERS);
@RequestLine("POST /api/v2/{key}/ft/upload_image")
@Headers("Content-Type: multipart/form-data")
Response uploadImage(@HeaderMap Map<String, String> headerMap,
@Param("key") String key,
@Param("image") File image);
After then, I wanted to add and use JAXRSContract.
But this code is not working
Builder formBuilder = Feign.builder()
.contract(new JAXRSContract())
.encoder(new FormEncoder())
.decoder(new JacksonDecoder())
.options(options)
.logger(new Slf4jLogger())
.requestInterceptor(new FeignRequestInterceptor())
.logLevel(Level.HEADERS);
@POST
@Path("/api/v2/{key}/ft/upload_image")
@Produces(MediaType.MULTIPART_FORM_DATA)
@Consumes(MediaType.MULTIPART_FORM_DATA)
Response uploadImage(@PathParam("key") String key,
@HeaderParam("account") String account
@Param("image") File image);
In the case of using the above code, I got the following error message.
feign.codec.EncodeException: class java.io.File is not a type supported by this encoder.
I think those two code have to execute as same way.
Is there has any problem on second code initialized with JAXRSContract?
or Is there has other way to upload file using FormEncoder and JAXRSContract?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the multipart upload example in the feign-form README and compare its FormEncoder setup with the JAXRSContract setup shown here. Trace how the uploadImage method's File parameter is interpreted by JAXRSContract and passed to FormEncoder. Done means the JAX-RS declaration can upload a File without the unsupported-type EncodeException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100