2017-04-08 66 views
-1

我在下面的代碼中寫下從其他域下載.CSV文件的代碼。如何解決離子2中的CORS起源問題

 const fileTransfer: TransferObject = this.transfer.create(); 

     let url = 'http://example.com' + data.filepath; 
     console.log(url); 

     fileTransfer.download(url, this.file.dataDirectory + 'Sample.csv').then((entry) => { 
      console.log('download complete: ' + entry.toURL()); 

     }, (error) => { 
      console.log("No file to download"); 

     }); 

它給了我下面的錯誤

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.com/sample.csv (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

回答

1

CORS是瀏覽器的安全功能,您可以從服務器的URL阻止。無論如何,當您在構建之後安裝應用程序時,移動設備上將不會顯示該問題。

+0

我正在使用'離子視圖'應用程序來測試設備上的'MyApp',但是當我點擊下載按鈕時什麼也沒有發生。沒有文件下載。 –