首页 > 解决方案 > 将文件上传到 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#.netajaxgoogle-chromefilesystems

解决方案


推荐阅读