如何在AngularJS下载中添加进度条?

时间:2016-07-08 07:17:08

标签: angularjs progress-bar

HTML code:

<form id="pdfForm" class="display-inline" method="POST" action="{{document.PdfActionUrl}}">
    <button uib-tooltip="Download PDF" type="submit" ng-disabled="document.CaseStudies.length == 0" class="uui-button button-action"><span class="icons-action icon-action-load"></span></button>
</form>

AngularJS代码:

$scope.jsonToDoc = function (doc) {
    document.PdfActionUrl = '/odata/DocumentsApi(' + document.Id + ')/API.DownloadPdf';

服务器端代码:

public HttpResponseMessage DownloadPdf([FromODataUri] Guid key)
{
    var document = _documentService.GetPdfDocument(key, Request.RequestUri.BaseUri(System.Configuration.ConfigurationManager.AppSettings["setting"]));

    HttpResponseMessage response = new HttpResponseMessage();
    response.Content = new StreamContent(document.Content);
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    {
        FileName = document.Name
    };

    return response;
}

我不确定哪种方法最适合这种情况以及如何计算实时下载。

0 个答案:

没有答案