]> BookStack Code Mirror - bookstack/commitdiff
Added streamed uploads for attachments
authorDan Brown <redacted>
Sat, 2 Apr 2022 17:46:48 +0000 (18:46 +0100)
committerDan Brown <redacted>
Sat, 2 Apr 2022 17:46:48 +0000 (18:46 +0100)
app/Http/Controllers/AttachmentController.php
app/Uploads/AttachmentService.php

index 7f5ffc8cb94e14b6b0d53c2a68f81920851a6f8c..0a092b63ae11385e4d67dae6218109b2e2f659fa 100644 (file)
@@ -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;
 
index 05e70a502bfdf6be55921b7e72cd86c95cd7ac77..ec02182bb118624fda0be7cdabbf7fde5eecadab 100644 (file)
@@ -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());