2

I'm using an Image field in Nova for the first time and found that previews were not displaying.

I am using DigitalOcean Spaces with the S3 driver for the relevant disk. It seemed that files were uploaded with private permissions and so the preview URL was not accessible.

Currently I have a simple Image field:

Image::make('Image')
  ->disk('spaces')
  ->storeOriginalName('image_name')
  ->storeSize('image_size')
  ->store(new PublicUpload),

That is using an "invokable" class (PublicUpload) that looks like this:

<?php

namespace App\Nova;

use Illuminate\Http\Request;

class PublicUpload
{
    public function __invoke(Request $request, $model, $attribute, $requestAttribute, $disk, $storagePath)
    {
        $currentFile = $request->file($attribute);

        return [
            $attribute => $currentFile->storePublicly($storagePath)
        ];
    }
}

However, StorePublicly just doesn't seem to be doing its job the way I have this set up. The images upload to the Spaces storage but they are still set as "private".

I realise I could probably just create a route to alter the preview URL in Nova but I have no reason to store these files privately and I know this should be possible.

I'd appreciate any help or advice at all. Thanks in advance.

Joe Spurling
  • 967
  • 11
  • 22
  • For now I've just generated some routes to access files via the API. I would still like to know why I'm unable to store files publicly though. – Joe Spurling Oct 29 '21 at 16:49

0 Answers0