Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My code for RESTful file upload :

@Path("/upload") 
@POST 
@Consumes("multipart/form-data") 
public String post(
    @FormDataParam("part") String s, 
    @FormDataParam("part") FormDataContentDisposition d) { 
    return s + ":" + d.getFileName(); 
}

When I try to upload a file using curl curl -X POST --form [email protected] url

I am getting a HTTP 415-Unsupported Media Type Error. What is wrong ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
110 views
Welcome To Ask or Share your Answers For Others

1 Answer

This can happen due to a couple of reasons. I managed to narrow down some of them.

  1. Your Content-Type header does not match with the one provided by the @Consumes header. Verify this with a proxy.

  2. You managed to stumble upon a bug that was fixed in Jersey 1.4 related to the FormDataParam annotation.

  3. You included jersey-bundle and jersey-server et all in the same binary and they are competing against each other.

  4. You are using @FormParam instead of @FormDataParam.

  5. Your @FormDataParam is unrecognized by the introspection API because of conflicts with jersey-multipart and other jersey jars. If one jar is of version 1.x make sure the other jars are on the same version. While debugging the jersey API code I noticed that these method annotations turn up blank (on jersey's code) if the jar versions are not uniform. All method parameters on the REST service are replaced by the body content of the POST request irrespective of which FormDataParam they are supposed to contain.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...