2015년 1월 1일 목요일

[AngularJS] Download different types of file

Good day!

I can't resolve my problem - create link to download attachment. 
A file I receive from SOAP service in xml and consequently I must create a link to download file.

What I have now:

In controller:
 
   //creating comments
    
for (var index in $scope.comments){
                        
var com = $scope.comments[index]
                        
if (com.z2AF_Work_Log01_attachmentName !==undefined){
                          
var a         = document.createElement('a');
                          a
.target      = '_blank';
                          a
.download    = com.z2AF_Work_Log01_attachmentName;
                          a
.innerText   = com.z2AF_Work_Log01_attachmentName;

                          
var blob = new Blob([atob(com.z2AF_Work_Log01_attachmentData) ],
                            
{ type : 'zip' });
                          
//com.href  = (window.URL || window.webkitURL).createObjectURL( blob );
                          a
.href = (window.URL ||window.webkitURL).createObjectURL( blob );;
                          com
.attachment_link = a.outerHTML;

                        
}
                      
}

Links created, but if I have not plain text (csv) a file after download is broken. When I download csv - all fine.

In template:
  
  .attach ng-bind-html="comment.attachment_link | notSanit"


Thanks.


댓글 없음:

댓글 쓰기