]> BookStack Code Mirror - bookstack/blobdiff - app/Uploads/ImageService.php
Add base64 image support
[bookstack] / app / Uploads / ImageService.php
index ee42e6e3345066ca26d9eac4449cc8ade2691610..010b531f1042d1714205474fc5437a9e6078f0be 100644 (file)
@@ -60,7 +60,7 @@ class ImageService
         int $resizeHeight = null,
         bool $keepRatio = true
     ) {
-        $imageName = $this->sanitizeFileName($uploadedFile->getClientOriginalName());
+        $imageName = $uploadedFile->getClientOriginalName();
         $imageData = file_get_contents($uploadedFile->getRealPath());
 
         if ($resizeWidth !== null || $resizeHeight !== null) {
@@ -109,6 +109,7 @@ class ImageService
             $storage->put($fullPath, $imageData);
             $storage->setVisibility($fullPath, 'public');
         } catch (Exception $e) {
+            \Log::error('Error when attempting image upload:' . $e->getMessage());
             throw new ImageUploadException(trans('errors.path_not_writable', ['filePath' => $fullPath]));
         }
 
@@ -139,7 +140,7 @@ class ImageService
         $name = str_replace(' ', '-', $name);
         $nameParts = explode('.', $name);
         $extension = array_pop($nameParts);
-        $name = implode('.', $nameParts);
+        $name = implode('-', $nameParts);
         $name = Str::slug($name);
 
         if (strlen($name) === 0) {
@@ -426,15 +427,4 @@ class ImageService
         $basePath = ($this->storageUrl == false) ? url('/') : $this->storageUrl;
         return rtrim($basePath, '/') . $filePath;
     }
-
-    /**
-     * Returns a sanitized filename with only one file extension
-     */
-    private function sanitizeFileName(string $fileName): string
-    {
-        $parts = explode('.', $fileName);
-        $extension = array_pop($parts);
-
-        return sprintf('%s.%s', implode('-', $parts), $extension);
-    }
 }