部署后无法通过API上传文件

我已经创建并测试了文件api。我的问题是使用者可以在我的本地计算机上工作,但部署后无法工作。错误:无法访问封闭的流!

[HttpPost]
    public async System.Threading.Tasks.Task<actionResult> InsertFile(httppostedfileBase file)
    {
        HttpClientHandler hndlr = new HttpClientHandler();
        hndlr.UseDefaultCredentials = true;
        using (var client = new HttpClient(hndlr))
        {
            var content = new MultipartFormDataContent();
            MemoryStream target = new MemoryStream();
            file.InputStream.CopyTo(target);
            byte[] data = target.ToArray();
            file.InputStream.Read(data,data.Length);
            var fileContent = new bytearraycontent(data);
            fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment") { FileName = file.FileName };
            content.Add(fileContent);
            var requesturi = "http://ServerName/FilesAPI/api/Values";
            var result = await client.PostAsync(requesturi,content);
            if (result.StatusCode == System.Net.HttpStatusCode.Created)
            {
               List<string> m = await result.Content.ReadAsAsync<List<string>>();
               if (m.FirstOrDefault() == "-3")
               {
                  return RedirectToaction("InsertWD","Home",new { fileID = id });
               }
            }
        }
        return View();
    }
szs1987 回答:部署后无法通过API上传文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2932156.html

大家都在问