注意這是有缺點的,不建議拿來存放大檔案會出現OOM
建議還是直接使用<a href="" downloads> 直接下載
action1
var pdfFile = "xxx.pdf"; FileContentResult file = File(pdfFile, "application/vnd.ms-excel"); Session["pdfFile"] = file; // 將檔案儲存在 Session
html
var filePath = "https://appxxx/" + filename //URL.createObjectURL(blob); window.location = '@Url.Action("index", "Default")';
action2
// byte 存session 直接下載PDF用 public ActionResult GetFile() { byte[] data = null; FileContentResult file = Session["pdfFile"] as FileContentResult; data = file.FileContents; string fName = "DownloadName.pdf"; Session["pdfFile"] = null; return File(data, "application/pdf", fName); }
沒有留言:
張貼留言