Nova-Filemanager icon indicating copy to clipboard operation
Nova-Filemanager copied to clipboard

Non-public images breaks preview

Open fedeisas opened this issue 4 years ago • 4 comments

If my bucket has non-public images, I'd like to generate signed URLs for previews, to avoid 403s on the frontend. Any suggestions on where to extend the library to get that behaviour? Thanks.

// src/Http/Services/NormalizeFile.php

/**
 * Returns the image or the svg icon preview.
 *
 * @return mixed
 */
private function getImage($mime, $extension = false)
{
    if (Str::contains($mime, 'image') || $extension == 'svg') {
        return $this->storage->url($this->storagePath);
    }

    $fileType = new FileTypesImages();

    return $fileType->getImage($mime);
}

fedeisas avatar Oct 29 '20 02:10 fedeisas

Same issue here) @fedeisas did you solve it?

gadimlie avatar Jan 25 '21 06:01 gadimlie

hi, all, I was investigating the flysystem api, and to be able to have the files non-public in s3, we need to create presigned requests. This can be done using

$this->storage->temporaryUrl($path,  '+5 minutes');

With this we can display the image in the preview.

marceloandrader avatar Feb 11 '21 15:02 marceloandrader

I think this should be done using a configuration to request this kind of temporary urls

marceloandrader avatar Feb 11 '21 15:02 marceloandrader

This is the patch I'm using for now:

+++ ../src/Http/Services/NormalizeFile.php
@@ -50,7 +50,7 @@
             'mime' => $this->getCorrectMimeFileType(),
             'path' => $this->storagePath,
             'size' => $this->getFileSize(),
-            'url'  => $this->cleanSlashes($this->storage->url($this->storagePath)),
+            'url'  => $this->cleanSlashes($this->storage->temporaryUrl($this->storagePath, '+5 minutes')),
             'date' => $this->modificationDate(),
             'ext'  => $this->file->getExtension(),
         ]);
@@ -145,7 +145,7 @@
     private function getImage($mime, $extension = false)
     {
         if (Str::contains($mime, 'image') || $extension == 'svg') {
-            return $this->storage->url($this->storagePath);
+            return $this->storage->temporaryUrl($this->storagePath, '+5 minutes');
         }

         $fileType = new FileTypesImages();

marceloandrader avatar Feb 11 '21 16:02 marceloandrader