流不是有效的资源文件

时间:2019-05-16 09:16:28

标签: c# .net asp.net-web-api asp.net-core resource-files

我正在将文件上传到Api,并尝试读取资源键和值。尝试读取文件时,出现异常。

System.ArgumentException: Stream is not a valid resource file.
at System.Resources.ResourceReader._ReadResources()
at System.Resources.ResourceReader.ReadResources()
at System.Resources.ResourceReader..ctor(String fileName)

下面是我尝试过的代码。

        [HttpPost]
    public async Task<ActionResult> Post(IFormFileCollection files)
    {
        try
        {
            files = this.Request.Form.Files;
            var tempFolder = Path.GetTempPath();

            foreach (var formFile in files)
            {
                string fileName = ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim('"');
                string filePath = Path.Combine(tempFolder, fileName);

                if (formFile.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await formFile.CopyToAsync(stream).ConfigureAwait(false);
                    }

                    var resReader = new ResourceReader(@filePath); // Throwing an exception.
                }
            }
        }
        catch (Exception ex)
        {
            throw;
        }

        return this.Ok("Success.");
    }

下面是请求Uri和文件。

enter image description here

我缺少任何配置吗?

0 个答案:

没有答案