我使用jQuery-File-Upload和 Spring MVC 之类的服务器部分。我尝试了这个例子,但它在 IE 9 浏览器中不起作用。它对我说:“您要保存还是打开对象”
客户端就像在示例中一样:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>jQuery File Upload Example</title>
</head>
<body>
<input id="fileupload" type="file" name="files[]" data-url="/fileUpload/1" multiple>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>
<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
</script>
</body>
</html>
服务器是:
@RequestMapping(value = "fileUpload/{id}", method = RequestMethod.POST)
@ResponseBody
public FileUploadResultDTO upload(MultipartFile file,
@PathVariable Long id,
Locale locale,
HttpServletRequest request) {
FileUploadResultDTO resultDTO = new FileUploadResultDTO();
// Logic saving file and return back response like object
return resultDTO;
}
public class FileUploadResultDTO {
private Long photoId;
private String pathToPhoto;
private String pathToSmallPhoto;
// getters/setters
}
它适用于除 IE 以外的所有浏览器