]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/AttachmentService.php
Skip intermediate login page with single provider
[bookstack] / app / Uploads / AttachmentService.php
index 05e70a502bfdf6be55921b7e72cd86c95cd7ac77..9d1f96ae42f99178f6b3fd10406a4572805b5943 100644 (file)
@@ -76,12 +76,12 @@ class AttachmentService
     /**
      * Stream an attachment from storage.
      *
-     * @return resource|null
      * @throws FileNotFoundException
+     *
+     * @return resource|null
      */
     public function streamAttachmentFromStorage(Attachment $attachment)
     {
-
         return $this->getStorageDisk()->readStream($this->adjustPathForStorageDisk($attachment->path));
     }
 
@@ -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());