这里使用 new window.FormData()
方式,代码也是考的同事的,他那边不限制文件类型,我使用的时候对一些jar exe等文件类型就不支持,目前自己试出来一些常见的格式,先做的上传文件类型限制,但还是想解决一下;问题具体表现为http响应302和一个200的,可以看截图:
这是我的上传文件的js:
//附件上传
attachFileChange: function() {
const fileTypes = "doc,docx,xls,xlsx,pdf,ppt,pptx,txt,jpg,jpeg,png,bmp,gif,zip,rar";
const fileTypeArray = fileTypes.split(",");
const attachFile = $("#attachFile").get(0).files[0];
/*
const filePathArray = attachFile.name.toLowerCase().split('.');
const fileType = filePathArray[filePathArray.length - 1];
if (_.indexOf(fileTypeArray, fileType) == -1) {
HyMessage({
message: `支持的附件格式【${fileTypes}】,当前格式:${fileType}。`,
type: 'warning'
});
return;
}
*/
const me = this;
const formData = new window.FormData();
formData.append("file", attachFile);
$.ajax({
type: "POST",
data: formData,
contentType: false,
processData: false,
url: $$pageContextPath+'dynamics/uploadDynamicsAttachFile?t='+new Date().getTime(),
success: response => {
//xxxxxx
},
});