This time I got bad luck with Stack Overflow, you guys are my last
resource, and pls be kind with a newbie. Here is the trouble: in my MEAN
application I need to provide a link to download a file (tif image), the
link must be hidden and not accessible by unauthorized users. So I came up
with the idea of keeping the files inside the server directory and let
Angular.js send with ng-click="download()" an $HTTP request to express.js
with the file ID to download. Here is my code that doesn't work, there are
no errors whatsoever, but I can't even get the download dialog box to open:
Client Side:
$scope.download=function(){
$http({method:'GET', url:'/download/'+image[0]['_id']}).
success(function(data, status, headers, config) {
var element = angular.element('<a/>');
element.attr({
href: 'data:attachment/tif;charset=utf-8,' + encodeURI(data),
target: '_self',
download:'test.tif'
})[0].click();
}).
error(function(data, status, headers, config) {
});
}
Template:
<a ng-href="#" target="_self" type="button" class="btn"
ng-click="download()">Download</a>
Server Side
app.namespace('/download/:documentID*', function() {
app.all('/', function(req, res, next){
res.download('images/download/test.tif', 'test.tif', function(err){
if (err) {
} else {
next();
}
});
});})
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.