欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

FormData上传文件同时附带其他参数

程序员文章站 2022-04-11 17:27:08
...
function sureaddmovie() {
	var formDate = new FormData();
	var file = document.getElementById("upload")[0].files[0];// 视频
	var moviename = $("input[name=moviename]").val();
	formDate.append("file",file);
	formDate.append("moviename",moviename);
	
	var progress;

	$.ajax({
		url : "/LearnJAVAwithXge01/uploadmovie",
		type : "POST",
		dataType : "text",
		// async:false,
		data : formDate,
		processData : false,
		contentType : false,
		/*
		 * beforeSend:function() { progress = layer.open({ type : 1, title :
		 * '提示', skin : 'addlanguage-calss',// 样式类名 closeBtn : 2, // 不显示关闭按钮
		 * shift : 2, area : [ '250px', '130px' ],// 宽高 shadeClose : false,
		 * resize : false, scrollbar : false, content : "视频正在上传,请稍后..." }); },
		 */
		success : function(result) {
			var arry = new Array();
			arry = result.split(",");
			if (arry[0] = "上传成功!") {
				var videopath = "F" + arry[2];
				uploadshowpic(videopath);
			} else {
				layer.alert(arry[0], {
					title : "提示"
				});
			}
		},
		error : function(error) {
			layer.alert("错误!", {
				title : "提示"
			});
		}
	});
}

后台代码:

public Object uploadmovie(
			@RequestParam(value = "file", required = false) MultipartFile multipartFile,
			HttpServletRequest request, String moviename) {
		
		String myfilename = moviename;