'File download link opens in new blank tab until I refresh the page
I send download link in an email in the following form:
https://example.com/download-file/<file-id-number>
In my controller I handle it like so:
public function download-file(Request $request)
{
$file_id = $request->id;
// get File model with all the parameters here (name, path, etc..)
try {
return Storage::disk('s3')->download($file->path, $file->name, [
'Content-Disposition' => 'attachment; filename="' . $file->name .'"',
'Content-Type' => 'text/xlsx',
]);
} catch (Exception $e) {
// handle exceptions
}
I added the correct route in web.php:
Route::get('download-file/{id}', 'Files\FilesController@download-file/{id}')->name('files.download-file')
When I click the link it opens a blank tab in the browser with Untitled in the address bar, and doesn't do anything. But then if I refresh the page, the address bar suddenly shows the real link, downloads the file then the tab closes.
Also, if I click the link and the Untitled tab opens, then if I move to another tab in the browser then come back, the Untitled once again changes the to the real link
What could cause that issue? No error in the browser, I see the file id in the browser's Network tab
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
