c# - 将文件上传到 WebApi 并保存,在 IE 中有效,但在 Chrome 中无效
问题描述
尝试将文件上传到 web api 并保存,当使用 IIS 在本地运行项目时,它会成功使用 Chrome 和 IE11 保存文件。
当我尝试保存时将项目部署到测试环境时:使用 Chrome 我得到“访问被拒绝”使用 IE 它正在工作。
如何使其也适用于 Chrome?
客户代码:
var data = new FormData();
var files = $("#fileUpload").get(0).files;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
data.append("UploadedImage", files[0]);
}
// Make Ajax request with the contentType = false, and procesDate = false
$.ajax({
type: "POST",
url: uriUser + "/UploadFile",
contentType: false,
processData: false,
data: data,
success: function (data) {
try {
showMsg(MessageType.Info, data);
closeWin();
}
catch (e) {
if (e.message == "") {
showMsg(MessageType.Error, msg_error);
}
}
},
error: function (response) {
console.error('DeleteRole failed :' + response);
}
});
服务器代码:
var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
// Some manipulation to get the FileName and the Path...
httpPostedFile.SaveAs(fileSavePath);
解决方案
推荐阅读
- c# - MVC WebApi 高级自定义路由
- azure - 自定义脚本扩展是否只能临时使用?
- javascript - 向后循环仅打印未定义
- css - 如何在 Django 中加载字体
- php - 电子邮件发送后如何得到回复。Symfony 4.3 邮件组件
- python - 查找大于或等于较短搜索列中每个值的较大列中的第一个值
- php - 如何在 laravel 中使用 dompdf 将 boucle 中的数据从控制器传递到查看
- django-rest-framework - 如何在 Django RESTFramework 中将查询集作为 JSON 响应返回?
- python - 尽管进行了转换,如何修复类型错误?
- html - 在 typescript 中将 JSON 对象转换为 html 表格格式