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.
@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.
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.
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
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];
}
}
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