$scope.downloadPDF = function (docId) {
//Need the code to add the authorisation header before transfer
var pdfURL = $rootScope.genericApiurl + 'servicetype/pdfDocument?docId=' + docId;
$window.location.href = pdfURL;
}
嘗試設置$ http.defaults.headers.common ['Authorization'] ='Basic'+ authdata;但不工作。In Angular需要在傳輸前設置授權標頭
這必須通過授權標題只,我不能轉讓我的令牌作爲參數,否則我需要更改網絡API只是爲了這次調用,這不是一個好的選擇,這也有安全問題。請分享,如果你有任何其他選擇,如使用$資源等。 – Santanu
哦,我現在瞭解你的情況。還有另一個選項,您將爲每個文件pdf生成一個下載令牌,其中包含過期時間和一些信息,令牌將被加密。在服務器端(你的API),你會得到令牌,然後你可以解密它並檢查這個令牌是否有效。如果有效,您將從api返回一個FileContent類型。例如。 yourdomain.com/document/aaa-bbb-ccc/download/xxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyy。 xxxxxxxxxxxxxxxxx.yyyyyyyyyyyyyyyyyyyyyyyy:令牌; aaa-bbb-ccc:documentId。 –
是的,你現在已經明白了,我只是實現了這種方法,它的作品好像有點奇怪。我會接受這個作爲我的解決方案,如果你可以在你的答案中詳細說明這一點。 – Santanu