bufferoverflow's avatar

Livewire temporary file upload directly to S3 is crashing

File uploads are working if using local disk but when switching to s3 driver, I get the following error:

Call to undefined method League\Flysystem\Cached\CachedAdapter::getClient()

// GenerateSignedUploadUrl.php

$command = $adapter->getClient()->getCommand('putObject', array_filter([
        'Bucket' => $adapter->getBucket(),
        'Key' => $path,
        'ACL' => $visibility,
        'ContentType' => $fileType ?: 'application/octet-stream',
        'CacheControl' => null,
        'Expires' => null,
 ]));

My config is the following:

    'temporary_file_upload' => [
        'disk' => 's3',  
        'rules' => ['required', 'file', 'max:40000'], 
        'directory' => 'livewire-tmp', 
        'middleware' => 'throttle:10,1',  
        'preview_mimes' => [  
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpeg', 'mpga', 'webp', 'wma'
        ],
    ],

I have this same s3 disk working for other uploads. It's just crashing for the temporary uploads from Livewire.

0 likes
6 replies
NOHHANGYEOL's avatar

config/filesystems.php

check your code

's3' => [ 'driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION'), 'bucket' => env('AWS_BUCKET'), 'visibility' => 'public', ],

1 like
bufferoverflow's avatar

Thanks for your contribution, but I'm already using s3 for other content, and it's working fine. I assume my aws config is correct.

daverydan's avatar

Did you ever get this sorted? I added s3 as my temp file upload disk, and started to get a CORS error when uploading to my S3 temp directory? Any ideas as to why? Thanks in advance!

bufferoverflow's avatar

Hey, sorry for the delay.

Just decided to re-try fixing this error. In my case, I couldn't find the solution yet, but I think I know how you can solve yours.

Try going to the s3 bucket permissions tab and add this cors JSON at the bottom of the page:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "https://example.com"
        ],
        "ExposeHeaders": []
    }
]
2 likes
bufferoverflow's avatar
bufferoverflow
OP
Best Answer
Level 7

The problems appear when you add cache to the s3 entry in the filesystems.php fille. I sent a pull request to the Livewire repo in order to fix this.

Please or to participate in this conversation.