adding header to http response in an action inside a controller in asp.net/mvc

前端 未结 5 2102
花落未央
花落未央 2021-02-13 18:14

I am streaming data from server to client for download using filestream.write. In that case what is happening is that I am able to download the file but it does not

5条回答
  •  情歌与酒
    2021-02-13 18:44

    public FileResult DownloadDocument(string id)
            {
                if (!string.IsNullOrEmpty(id))
                {
                    try
                    {
                        var fileId = Guid.Parse(id);
    
                    var myFile = AppModel.MyFiles.SingleOrDefault(x => x.Id == fileId);
    
                    if (myFile != null)
                    {
                        byte[] fileBytes = myFile.FileData;
                        return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, myFile.FileName);
                    }
                }
                catch
                {
                }
            }
    
            return null;
        }
    

提交回复
热议问题