简体   繁体   English

在IE9中使用jquery-file-upload时出现415错误(空媒体类型)

[英]415 error (null media type) when use jquery-file-upload in IE9

I use jquery-file-upload in my project and it works well in chrome. 我在项目中使用jquery-file-upload,在chrome中效果很好。 But in IE, it return (415 - Unsupported Media Type) (INFO: The system cannot find any method in the ...OwnFileAPI class that consumes null media type . Verify that a method exists that consumes the media type specified.) 但是在IE中,它返回(415-不支持的媒体类型)(信息:系统无法在... OwnFileAPI类中找到消耗空媒体类型的任何方法。请验证是否存在使用指定媒体类型的方法。)

Here is the code snippet : 这是代码片段:

JQuery : jQuery的:

$('#file-upload-form').fileupload({
  sequentialUploads : true,
  add : function(e, data) {
    ...
    data.submit();
  },
  submit : function(e, data) {
   ...
  },
  progress : function(e, data) {
    ...
  },
  fail : function(e, data) {
    ...
  },
  done : function(e, data) {
    ...
  }
});

JSP : JSP:

<form class="row-fluid" id="file-upload-form" method="post" enctype="multipart/form-data" action="<c:url value="/resources/api/user/files/own/csrfToken/"></c:url><wm:csrfToken/>" target="files-upload-target">
    <span class="btn fileinput-button" id="file-upload-btn">
        <strong><fmt:message key="files.action.upload"/></strong>
        <input type="file" id="file-uploader" name="ownFile" tabIndex="-1">
    </span>

</form>

JAVA : JAVA:

@CSRF
@Path(PathConst.OWN_FILE_API_CSRFTOKEN)
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
public String upload(@PathParam("csrfToken") String csrfToken, InMultiPart inMP) {
    ......
}

Please provide some pointers to resolve this issue...THX! 请提供一些指示来解决此问题... THX!

If my assumption is correct, then you might submitting the file with the help of the ajax request. 如果我的假设是正确的,那么您可以在ajax请求的帮助下提交文件。 While submitting the file through ajax request you have to assign the request headers like content-type and content-disposition headers and you also have to send the content of the file as the boundary separated value as how the normal form submission works. 通过ajax请求提交文件时,您必须分配请求标头(例如content-type和content-disposition标头),并且还必须像正常表单提交方式一样将文件内容作为边界分隔值发送。

You can also refer to jQuery Ajax File Upload 您也可以参考jQuery Ajax文件上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM