如何在Javascript中获得C#FileContentResult响应?

问题描述

我有一个C#Web API,它返回FileContentResult。这是我的代码

 [HttpGet]
    [Route("Download")]
    public async Task<ActionResult<DownloadResponse>> DownloadFiles(int fileDocumentId)
    {
            var file = ... ; // code removed for brevity
            return File(file.FileData,file.FileType,file.FileName);
    }

public class DownloadResponse
{
    public string FileType { get; set; }
    public byte[] FileData { get; set; }
    public string FileName { get; set; }
}

和我的前端Javascript,我设法调用了Web API并能够获得响应。

function download(id) {
    fetch(`https://localhost:xxx/api/file/download?fileDocumentId=11`)
        .then(response => {
            return response
        })
        .then(result => {
            console.log(result);                
        })
        .catch(function (error) {
            console.log('Request failed',error)
        });
}

当我console.log(result);时,有很多属性。哪个属性具有响应数据,以便我可以查看FileDataFileName数据?

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)