我有一个文件流在我的控制器。现在我想下载这样的文件流为file。我的代码如下....
<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=="
我认为你使用javascript Canvas。首先将流数据设置为canvas drawImage方法,然后下载它。例如:
HTML<canvas id="canvas"></canvas>
Javascript var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var img = new Image();
img.onload = function() {
context.drawImage(this, 0, 0, canvas.width, canvas.height);
}
img.src="data:image/gif;base64,R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==";
var dataURL = context.toDataURL('image/png');
对不起!我没有给你完整的代码,因为我现在很忙。我觉得你应该这样用