【问题标题】:restful image upload exceptionrestful 图片上传异常
【发布时间】:2011-10-06 06:06:50
【问题描述】:

我有一个安静的界面,如下所示。 我正在尝试使用 jaxrs 界面上传图像,但遇到错误

    @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);
            }

当我使用此表格提出要求时

<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>

我收到此错误 - 客户端发送的请求在语法上不正确 (java.lang.RuntimeException: Could find no Content-Disposition header within part).


我忘了写,我在mvc端使用Springmvc,它可能与spring mvc块有关?

【问题讨论】:

  • 您能否提供来自服务器的堆栈跟踪或其他错误日志记录?此外,stackoverflow.com/questions/6137444/… 可能是相关的。
  • 当我从它提供的 html 页面提交时,它不会进入服务内部(java.lang.RuntimeException:在部分中找不到 Content-Disposition 标头)。这个错误没有堆栈跟踪或日志

标签: java rest jersey jax-rs


【解决方案1】:

如下更改 REST 服务签名可能会解决您的问题

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

【讨论】:

  • 感谢您的回复,但 FormDataContentDisposition 类在 jersey 内,我们的项目正在使用 jax-rs,我们不能同时使用 jersey 和 jaxrs,因为 2 jar 正在破裂谢谢
  • 泽西岛不是 JAX-RS 的实现吗?见wikis.sun.com/display/Jersey/Main
  • 是的,你是对的,但是在使用 FormDataContentDisposition 时,我需要添加 jersey.jar,当我添加这个 jar 时,tomcat donor 运行时会出现太多异常,当我擦除它运行的球衣时,我不明白问题
猜你喜欢
  • 2015-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 2011-10-01
  • 2020-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多