From cb770c534d4d1ac776fb78126fee7b46f57a2f19 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 2 Apr 2022 18:46:48 +0100 Subject: [PATCH] Added streamed uploads for attachments --- app/Http/Controllers/AttachmentController.php | 1 - app/Uploads/AttachmentService.php | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php index 7f5ffc8cb..0a092b63a 100644 --- a/app/Http/Controllers/AttachmentController.php +++ b/app/Http/Controllers/AttachmentController.php @@ -10,7 +10,6 @@ use BookStack\Uploads\AttachmentService; use Exception; use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Storage; use Illuminate\Support\MessageBag; use Illuminate\Validation\ValidationException; diff --git a/app/Uploads/AttachmentService.php b/app/Uploads/AttachmentService.php index 05e70a502..ec02182bb 100644 --- a/app/Uploads/AttachmentService.php +++ b/app/Uploads/AttachmentService.php @@ -223,8 +223,6 @@ class AttachmentService */ protected function putFileInStorage(UploadedFile $uploadedFile): string { - $attachmentData = file_get_contents($uploadedFile->getRealPath()); - $storage = $this->getStorageDisk(); $basePath = 'uploads/files/' . date('Y-m-M') . '/'; @@ -233,10 +231,11 @@ class AttachmentService $uploadFileName = Str::random(3) . $uploadFileName; } + $attachmentStream = fopen($uploadedFile->getRealPath(), 'r'); $attachmentPath = $basePath . $uploadFileName; try { - $storage->put($this->adjustPathForStorageDisk($attachmentPath), $attachmentData); + $storage->writeStream($this->adjustPathForStorageDisk($attachmentPath), $attachmentStream); } catch (Exception $e) { Log::error('Error when attempting file upload:' . $e->getMessage());