How to initialize file download from an external server?

前端 未结 3 1113
陌清茗
陌清茗 2020-12-29 00:16

I have an MVC controller method defined like this:

public ActionResult GetPdf(string filename)
        {
            var pdfDownload = File(\"~/Content/Gene         


        
3条回答
  •  -上瘾入骨i
    2020-12-29 00:24

    You could just redirect the user at the remote report; if that isn't an option, you will need to proxy it:

    byte[] blob;
    using(var client = new WebClient()) {
        blob = client.DownloadData(remoteUrl);
    }
    return File(blob, "application/pdf", "report1.pdf");
    

    the above assumed the file isn't very big; a more robust implementation would fetch and send in chunks.

提交回复
热议问题