将文件流作为angularjs中的文件下载

时间:2015-10-08 04:00:19

标签: javascript angularjs stream

我的控制器中有一个文件流。现在我想下载这样的文件流作为文件。我的代码如下......

<file-download file-data="{{uploadedFl.fileSrc}}"  filename="{{uploadedFl.fileName}}">
</file-download>

JS

 .directive('fileDownload', function() {
     return {
         restrict: 'E',
         template: '<a target="_self" href="" class="btn btn-primary" ng-click="downloadData()" > <i class="fa fa-download"></i></a>',
         scope: true,
         link: function(scope, element, attr) {

             var anchor = element.children()[0];
             $(anchor).attr({
                 href: attr.fileData,
                 download: attr.filename
             });
             // Also overwrite the download pdf function to do nothing.
             scope.downloadData = function() {

             };
         }
     }
 }); 

文件流在下面给出..

"data:text/plain;base64,I...AgICAgfQ=="

1 个答案:

答案 0 :(得分:0)

我认为你使用javascript Canvas。首先将流数据设置为canvas drawImage方法然后下载它。喜欢:

HTML

res1 <- Reduce("+",lapply(dat, function(x) {
              x[2,][x[1,]!=0] <- 0
              replace(x, which(x==99), 0)}))


res2 <- rbind(res1, type1_0= colSums(!do.call(rbind, lapply(dat, `[`, 1,))))


res2
#        A B C D E F G H
#type1   1 0 0 0 1 0 0 0
#type2   0 0 0 0 2 0 0 0
#type1_0 1 0 0 0 1 0 0 0

的Javascript

<canvas id="canvas"></canvas>

对不起!我没有给你完整的代码,因为我现在很忙。我想你这样用。