diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 92b20da94..218a9103a 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -970,7 +970,10 @@ class DialogController extends AbstractController return Redirect::to(FileContent::toPreviewUrl($array)); } // - return Response::download(public_path($array['path']), $array['name']); + $filePath = public_path($array['path']); + return Response::streamDownload(function() use ($filePath) { + echo file_get_contents($filePath); + }, $array['name']); } /** diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 1cc54eceb..57fb098ae 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -1175,7 +1175,7 @@ class ProjectController extends AbstractController if (empty($file) || !file_exists(storage_path($file))) { return Base::ajaxError("文件不存在!", [], 0, 502); } - return response()->download(storage_path($file)); + return Response::download(storage_path($file)); } /** @@ -1385,7 +1385,10 @@ class ProjectController extends AbstractController ])); } // - return Response::download(public_path($file->getRawOriginal('path')), $file->name); + $filePath = public_path($file->getRawOriginal('path')); + return Response::streamDownload(function() use ($filePath) { + echo file_get_contents($filePath); + }, $file->name); } /** diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 1c51103c8..40eddb365 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -14,6 +14,7 @@ use Guanguans\Notify\Factory; use Guanguans\Notify\Messages\EmailMessage; use Madzipper; use Request; +use Response; use Session; /** @@ -990,7 +991,7 @@ class SystemController extends AbstractController if (empty($file) || !file_exists(storage_path($file))) { return Base::ajaxError("文件不存在!", [], 0, 502); } - return response()->download(storage_path($file)); + return Response::download(storage_path($file)); } /** diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 2ab2c3cff..5b290b457 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -17,6 +17,7 @@ use Hhxsv5\LaravelS\Swoole\Task\Task; use LasseRafn\InitialAvatarGenerator\InitialAvatar; use Redirect; use Request; +use Response; /** @@ -269,7 +270,7 @@ class IndexController extends InvokeController if (preg_match("/^\d+\.\d+\.\d+$/", $genericVersion)) { $filePath = public_path("uploads/desktop/{$genericVersion}/{$name}"); if (file_exists($filePath)) { - return response()->download($filePath); + return Response::download($filePath); } } } @@ -317,7 +318,7 @@ class IndexController extends InvokeController $userAgent = strtolower(Request::server('HTTP_USER_AGENT')); if ($ext === 'pdf' && (str_contains($userAgent, 'electron') || str_contains($userAgent, 'chrome'))) { - return response()->download($file, $name, [ + return Response::download($file, $name, [ 'Content-Type' => 'application/pdf' ], 'inline'); } diff --git a/app/Models/FileContent.php b/app/Models/FileContent.php index 85b530689..96b2c0467 100644 --- a/app/Models/FileContent.php +++ b/app/Models/FileContent.php @@ -85,7 +85,7 @@ class FileContent extends AbstractModel * @param File $file * @param $content * @param $download - * @return array|\Symfony\Component\HttpFoundation\BinaryFileResponse + * @return array|\Symfony\Component\HttpFoundation\StreamedResponse */ public static function formatContent($file, $content, $download = false) { @@ -93,9 +93,13 @@ class FileContent extends AbstractModel $content = Base::json2array($content ?: []); if (in_array($file->type, ['word', 'excel', 'ppt'])) { if (empty($content)) { - return Response::download(public_path('assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type)), $name); + $filePath = public_path('assets/office/empty.' . str_replace(['word', 'excel', 'ppt'], ['docx', 'xlsx', 'pptx'], $file->type)); + } else { + $filePath = public_path($content['url']); } - return Response::download(public_path($content['url']), $name); + return Response::streamDownload(function() use ($filePath) { + echo file_get_contents($filePath); + }, $name); } if (empty($content)) { $content = match ($file->type) { @@ -124,7 +128,9 @@ class FileContent extends AbstractModel if ($download) { $filePath = public_path($path); if (isset($filePath)) { - return Response::download($filePath, $name); + return Response::streamDownload(function() use ($filePath) { + echo file_get_contents($filePath); + }, $name); } else { abort(403, "This file not support download."); }