2017-08-09 65 views
1

我有一個應用程序,我試圖從服務器上下載文件。在後端有Laravel 5.2,但在前端AngularJS 1.6。Angular,Laravel - 下載文件

下面我告訴我的方法在控制器,它應該將文件下載:

public function getCaseFile(Request $request){ 

      $caseId = $request->caseId; 
      $fileId = $request->fileId; 
      $path = $this->caseFiles->getCaseFilePath($caseId,$fileId); 
      $headers = [ 
      'Content-Type' => 'application/png', 
      ]; 

     return response()->download($path,"adsa.png",$headers); 


    } 

路由到該方法是:

Route::get('/cic/upload/getCaseFile/{caseId}/{fileId}','\App\Http\Controllers\CicCore\[email protected]'); 

當我試圖讓瀏覽器文件,一切都好。下面我顯示的鏈接:

http://dev.cic:8004/cic/upload/getCaseFile/232551/496 

問題是當我在Angular應用程序中下載文件時。 enter image description here

Apllication被重定向到鏈接:

http://dev.cic:8004/ 

我不知道什麼是錯的事。有人可能知道這有什麼問題嗎?我會非常感激的幫助。最好的問候

+0

你有沒有'$的var_dump($請求 - > caseId)'來檢查'caseId'和'fileId'進來請求? – Sajal

回答

1

準備好你的鏈接是這樣的:

<a target="_self" href="example.com/uploads/asd4a4d5a.pdf" download="fileuploader.png">fileuploader.png</a> 

Angular Doc Link