上传api无法在IIS上运行的文件

时间:2016-09-14 06:15:58

标签: c# asp.net-mvc iis asp.net-core asp.net-web-api2

我想用api上传文件,但我还需要发送ID'。 相同的代码在本地工作,但不在IIS上工作。

        [HttpPost("{id}")]
        [Route("Upload/{id}")]
        public async Task<IActionResult> Upload(int id)
        {
            using (var client = new HttpClient())
            {
                foreach (var file in Request.Form.Files)
                {
                    // . . . more logic    
                }
            }

            return new OkResult();
        }

在本地: enter image description here 在IIS上 enter image description here

1 个答案:

答案 0 :(得分:-1)

我找到了解决办法,这是非常愚蠢的。

在TypeScript中的客户端上我有。

 this.$upload.upload({
                url: '/api/transfer/upload/' + this.id,
                method: 'POST',
                headers: { 'Content-Type': 'multipart/form-data' },
                file: file,
                fileName: file.name,
            })...

而不是

 this.$upload.upload({
                url: 'api/transfer/upload/' + this.id,
                method: 'POST',
                headers: { 'Content-Type': 'multipart/form-data' },
                file: file,
                fileName: file.name,
            })

在网址路径中只有一个SLASH而不在IIS上工作!

相关问题