在springmvc下上传文件request.getInputStream();无法获取数据解决方法
request.getInputStream(); 该方法无法获取数据,但是debug 的request对象inputstreama中buffer【bb】 获取到数据,
原因是由于在springmvc配置文件中存在
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize"> <value>5242880</value> </property> </bean>
拦截配置,这样我们虽然获取了byte流但是却无法正常读取,这时可以采用springmvc 自带的方法(以下):
public String springupload( @RequestParam("uploadfile")MultipartFile[] ajaxuploadfile, HttpServletRequest request, HttpServletResponse response, Model model) {
主要是通过ajaxuploadfile来进行操作。如果不使用spring自带的文件上传的方法可以通过request.getInputStream();方法。但是,通过该方法读取会有额外的数据需要自己处理:
------WebKitFormBoundaryl7Arc1DpH0n7564m Content-Disposition: form-data; name="uploadfile"; filename="test.txt" Content-Type: text/plain test test test test test test test test test test test test test test test test test test test test ------WebKitFormBoundaryl7Arc1DpH0n7564m--