php - Download file from cloud disk (S3) with Laravel 5.1 -


i'm having problems generating file download response in laravel 5.1 while trying download file amazon s3.

this controller action:

/**  * @param getrequest $request  * @return \symfony\component\httpfoundation\response  */ public function get(getrequest $request) {     $fileentry = $this->filerepository->find();     $file = storage::disk('s3')->get('projects/'.$fileentry->project.'/'.$fileentry->name);      return $this->responddownload($file, $fileentry->name, $fileentry->type); } 

and responddownload method:

/**  * respond file download.  *  * @param $filecontent  * @param $filename  * @param $mime  * @return \symfony\component\httpfoundation\response  */ public function responddownload($filecontent, $filename, $mime) {     return (new response($filecontent, 200))         ->header('content-type', $mime)         ->header('content-disposition', 'attachment; filename="'.$filename.'"'); } 

if open developer tools can see response successful , content set file content, browser not prompting save file somewhere.

how can solve problem? wrong headers?

edit

i tried making streamed response browser still not showing save file modal.

public function responddownload($filecontent, $filename, $mime) {     return (new streamedresponse(function() use ($filecontent)     {         echo $filecontent;     }, 200, [         'content-type' => $mime,         'content-disposition' => 'attachment; filename="'.$filename.'"'     ])); } 

edit 2

response headers: response headers

response content: response content

the actual problem caused how sent download request server.

previously making ajax request server , wasn't making browser prompt me save downloaded file.

in order fix had start download request a tag.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -