restful image upload exception

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

I have a restful interface as shown below. I am trying to upload an image using jaxrs interface but I am faced with an error

    @POST         @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})         @Path("createUserphotoDirectory/{userid}/{serverName}")         @Consumes("multipart/form-data")         public String createUserDirectory(@PathParam("userid") Long userid,                    @PathParam("serverName") String serverName,                    MultipartFormDataInput input) {                 System.out.println("1");                photoService.createServerImages(userid,serverName,input);                return responseMessageSource.getMessage("SUCCESSFULL_CRATED_ALBUM",null,null);             } 

When I request using this form

<html> <body>     <h1>JAX-RS Upload Form</h1>      <form action="/AlbumApplication/rest/createUserphotoDirectory/1/FeedServer" method="post" enctype="multipart/form-data">         <p>         Select a file : <input type="file" name="uploadedFile" size="50" />        </p>         <input type="submit" value="Upload It" />     </form>  </body> </html> 

I get this error - The request sent by the client was syntactically incorrect (java.lang.RuntimeException: Could find no Content-Disposition header within part).


i forgot to write ,i use Springmvc at mvc side,it may be pertain spring mvc block?

回答1:

Changing the REST service signature as the following may solve your problem

public String createUserDirectory(@PathParam("userid") Long userid,          @PathParam("serverName") String serverName,           @FormDataParam("uploadedFile") File file,          @FormDataParam("uploadedFile") FormDataContentDisposition disposition) { 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!