commonsmultipartresolver ajax,java - Spring MVC - Multipart file upload with Ajax (Could not parse m...

I'm trying to upload a multipart file using Ajax, Spring MVC 3.2.0, Tomcat 8.0.9, but can't get it work. I read a lot of blogs and similar posting here on stackoverflow (Spring upload file problems, MultipartConfig with Servlet 3.0 on Spring MVC, …) which seem to have similar causes but couldn't figure out how to solve it. The weird thing is that the upload works when the file is smaller than 1MB, but when ever the recorded video exceeds that size, the following error is raised:

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null

org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:163)

org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:139)

org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:110)

In the following you can see all the configurations I made:

The AJAX POST-Request:

var videoBlob = e.data;

var pathArray = window.location.pathname.split( '/' );

var userID;

for (i = 0; i < pathArray.length; i++) {

if (pathArray[i].toString() == "edit"){

userID = pathArray[i+1];

}

}

var fd = new FormData();

fd.append('fname', 'video');

fd.append('data', videoBlob);

$.ajax({

url: '/user/edit/uploadVideo/' + userID,

data: fd,

processData: false,

contentType: false,

type: 'POST',

success: function(data)

{

$('#result').html(data + "uploaded by FormData!");

}

});

The web.xml

contextConfigLocation

classpath*:root-context.xml

spring.profiles.default

common

org.springframework.web.context.ContextLoaderListener

appServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath*:servlet-context.xml

1

appServlet

/

springMultipartFilter

springMultipartFilter

org.springframework.web.multipart.support.MultipartFilter

springMultipartFilter

/*

The servlet-context.xml

de.talentwuerfel

update

org.hibernate.dialect.MySQL5Dialect

true

class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

The root-context.xml where I defined the MultipartResolver

The Java-Controller

@RequestMapping(value = "/edit/uploadVideo/{id}", method = RequestMethod.POST)

public @ResponseBody String uploadVideo(@PathVariable long id, MultipartHttpServletRequest request, HttpServletResponse response) throws IOException {

//.... file handling

}

How can I solve this problem?

EDIT:

I tried the suggested approach and used the Servlet implementation to manage my video-file upload. The following adjustments have been made, but it's still resulting in a similar error:

Adjusted @Controller:

@RequestMapping(value = "/edit/uploadVideo/{id}", method = RequestMethod.POST)

public String uploadVideo(@PathVariable long id, @RequestParam("data") Part file) {

//...

}

The root-controller has been deleted and I added the multipartResolver to the servlet-context.xml

The tag was in the web.xml has been extended by the following Multipart-Configuration:

appServlet

org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath*:servlet-context.xml

1

/tmp

20848820

418018841

1048576

However, I'm still getting an exception and can't upload a blob file larger than 1MB:

Could not parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)

org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822)

javax.servlet.http.HttpServlet.service(HttpServlet.java:644)

org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)

javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

I implemented a similar file upload where a single file was simply picked and it totally worked to send large files while using the same configuration. So I believe it has rather something to do with the Ajax POST or the attached blob file?!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值