Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aarontharker's avatar

401 error on livewire uploads

When I try to upload a file on the production server the upload goes to 100% and then says error uploading. If I check the browser console it shows the upload failed because of a 401 error. I thought this may have been a signed url issue as the requests are going through Cloudflare, so I turned off Cloudflare proxying - no change. I set the following in bootstrap/app.php - no change.

->withMiddleware(function (Middleware $middleware) {
        $middleware->trustProxies(at: ['*']);
    })

finally I commented out the check for a signed url in Livewire's src file just to be sure this was not the issue

vendor/livewire/livewire/src/Features/SupportFileUploads/FileUploadController.php

//abort_unless(request()->hasValidSignature(), 401);

What else could be causing this issue?

0 likes
8 replies
aarontharker's avatar

@jlrdw Thanks for the reply. The first one is about auto-minify on Cloudflare - I already disabled this when I turned off Cloudflare proxying and the second is the signed URL issue - which I have confirmed is not my issue by commenting out the check for a signed URL.

aarontharker's avatar
aarontharker
OP
Best Answer
Level 2

So I was runnning it behind Octane/FrankenPHP and it appears that was causing the issue. I've not found a way to rectify it as of yet but turning off Octane has worked for the time being.

monodever's avatar

I use octane with roadrunner and solve this problem

You see 401 livewire error when upload image - because hasCorrectSignature() return error. If you try to debug this, you can see that original method \request()->getUri() or another methods - return "http". My host have "https", but livewire check "http" - its a main problem

I check all points and methods to set https, but it not works, because nginx return "http". You can check this it headers with \request()->headers->all() at forwarded-proto

I set strict https in nginx.conf proxy_set_header X-Forwarded-Proto https; or correctly set up nginx ssl settings

It works for me and my production

1 like
kansai's avatar

I found the way that can help with overriding livewire/upload-file:

namespace App\Providers;

use App\Http\Controllers\CustomLivewireController;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class LivewireOverrideServiceProvider extends ServiceProvider
{
           public function boot(): void
           {
                 $this->overrideRoutes();
           }

           public function overrideRoutes(): void
           {
                  Route::post('/livewire/upload-file', [CustomLivewireController::class, 'handle'])
                             ->name('livewire.upload-file')
                             ->middleware('web');
           }
}

and in controller:

namespace App\Http\Controllers;

use Livewire\Features\SupportFileUploads\FileUploadConfiguration;
use Livewire\Features\SupportFileUploads\FileUploadController;

class CustomLivewireController extends FileUploadController
{
        public function handle(): array
        {
                 $disk = FileUploadConfiguration::disk();

                 $filePaths = $this->validateAndStore(request('files'), $disk);

                  return ['paths' => $filePaths];
        }
}

this is worked for me

1 like
AzafoCossa's avatar

I tried this but didn't solve my problem. Using Laravel 13 & Livewire 4.

victoriopui's avatar

I'm recently encounter this issue, I found out because I haven't configure ssl on nginx server, although on client browser is read as https, on laravel side still read as http. The solution is to configure ssl on nginx and configure the cloudflare on Domain > SSL/TLS > Overview > Configure > Custom SSL/TLS and set to Full (Strict) which previously set to Flexible

Please or to participate in this conversation.