轻量服务器,post文件上传请求大于50k失败。但vs调试及其他服务器部署调试都是成功的,不清楚原因?
前端代码:
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<input type="file" id="img_upload" accept="image/*" mutiple="mutiple" capture="camera" />
<button onclick="getImgBase64()"></button>
<script src="/jquery-3.5.1.min.js"></script>
<script type="text/javascript">
function getImgBase64() {
var fileName = new Array();
const inputFile = document.getElementById('img_upload');
if (inputFile.files.length == 0) {
return "";
}
$.each(inputFile.files, function (i) {
var myData = new FormData();
myData.append("file", inputFile.files[i]);
$.ajax({
type: 'POST', //请求方式
url: '/api/Default/upLoadFile',//请求路径
data: myData, //将对象转为application/json的格式字符串 JSON.stringify({ base64: pf})
dataType: "text",
async: false, //同步执行
//contentType: "application/json",//"application/json",
contentType: false,
processData: false, // 不处理数据,因为FormData 已经包含了文件数据
success: function (arg) {
alert(arg);
fileName.push(arg);
},
error: function () {
console.log("后台处理错误");
}
});
})
return fileName.join(',');
}
</script>
</body>
</html>
后端api
// GET: api/Default/GetInspectMenu?teacherId=XXXX
[HttpPost("upLoadFile")]
public string upLoadFile(IFormFile file)//获取考试成绩基本信息 IList<GradesBasic>
{
string fileName;
var currentTime = DateTime.Now.ToString("yyyymmddhhmmss");
fileName = currentTime + getRandomString(6) + "." + file.FileName.Split(".")[1];
using (var stream = new FileStream(System.IO.Directory.GetCurrentDirectory() + @"\wwwroot\perRecord\" + fileName, FileMode.CreateNew))
{
file.CopyTo(stream);
}
return fileName;
}
相似问题