【发布时间】:2018-06-23 11:03:36
【问题描述】:
我使用的是 spring 4.3.1,我将使用 ng-file-upload 库上传文件。 这是我的 javascript 代码,当我将 javascript 代码连接到 php 服务器时,它运行良好。
var promise = Upload.upload({
url: url + "upload",
method: 'POST',
file: file,
ignoreLoadingBar: true
}).success(function(response) {
flatForm.jsonForm = response.jsonForm;
flatForm.xmlForm = response.xmlForm;
}).error(function(response) {
$rootScope.$broadcast('veil:hide', {});
});
我在 /web-inf/lib 文件夹中附加了 commons-io-2.4.0.0.jar 和 commons-fileupload-1.3.1.jar。 e 我在 applicationContext.xml 文件中添加了 multipartResolver。
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1000000000" />
</bean>
这是我的控制器类。
@ResponseBody
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file == null || file.isEmpty()) {
throw new Exception("No file was sent.");
}
}
但是当我上传文件时,我得到了这样的错误。
Required MultipartFile parameter 'file' is not present
我该如何解决这个问题? 请帮我。 感谢您的观看。
【问题讨论】:
标签: java spring spring-mvc ng-file-upload