How to download a file to browser from Azure Blob Storage

后端 未结 4 679
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 23:47

I\'m already successfully listing available files, but I needed to know how I could pass that file down to the browser for a user to download without necessarily saving it t

4条回答
  •  无人及你
    2020-11-30 00:46

    Once the user clicks a file the server responds with this

    var blob = container.GetBlobReferenceFromServer(option);
    
    var memStream = new MemoryStream();
    blob.DownloadToStream(memStream);
    
    Response.ContentType = blob.Properties.ContentType;
    Response.AddHeader("Content-Disposition", "Attachment;filename=" + option);
    Response.AddHeader("Content-Length", blob.Properties.Length.ToString());
    Response.BinaryWrite(memStream.ToArray());
    

    HUGE thanks to Dhananjay Kumar for this solution

提交回复
热议问题