File Uploading problem 401 Error.

[Everything works fine In local Environment] Hello, I have this problem I'm using ngrok-free to host my app locally to test my app in online. Everything work's fine like loading image assets but when I try to Upload image using FileUpload it cause problem. btw I didn't face this problem If I use normal upload Like using blade and controller. Here Is My setup that usually work with normal app. File Upload
FileUpload::make('thumbnail')
->image()
->imageEditor()
->imageCropAspectRatio('16:9')
->disk('products')
])->columnSpan(1)
FileUpload::make('thumbnail')
->image()
->imageEditor()
->imageCropAspectRatio('16:9')
->disk('products')
])->columnSpan(1)
AppServiceProvider
public function boot(): void
{
if (\App::environment(['production', 'local'])) {
URL::forceScheme('https');
}
}
public function boot(): void
{
if (\App::environment(['production', 'local'])) {
URL::forceScheme('https');
}
}
Env
APP_NAME=asm
APP_ENV=local
APP_KEY=base64:szgyQjydWBZVod7BWujDG/ZYa8CIa94UmPKNeekbgko=
APP_DEBUG=true
APP_URL=https://recently-amusing-hedgehog.ngrok-free.app

ESSION_DOMAIN=.ngrok-free.app
SESSION_SECURE_COOKIE=true

SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1,::1,ngrok-free.app,https://recently-amusing-hedgehog.ngrok-free.app
APP_NAME=asm
APP_ENV=local
APP_KEY=base64:szgyQjydWBZVod7BWujDG/ZYa8CIa94UmPKNeekbgko=
APP_DEBUG=true
APP_URL=https://recently-amusing-hedgehog.ngrok-free.app

ESSION_DOMAIN=.ngrok-free.app
SESSION_SECURE_COOKIE=true

SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1,::1,ngrok-free.app,https://recently-amusing-hedgehog.ngrok-free.app
No description
Solution:
I think ->trustProxies() is the right way. I think you can add your ngrok IP to limit this, but I don't think there is a high risk when you keep your ngrok URL to yourself.
Jump to solution
3 Replies
Nick Ruddra
Nick RuddraOP2w ago
Okey I found two solution first one is using bootstrap\app.php
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies("*");
})
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies("*");
})
second one Is using AppServiceProvider
if($this->app->environment('production', 'local')) {
url::forcescheme('https');
request()->server->set('https', request()->header('x-forwarded-proto', 'https') == 'https' ? 'on' : 'off');
}
if($this->app->environment('production', 'local')) {
url::forcescheme('https');
request()->server->set('https', request()->header('x-forwarded-proto', 'https') == 'https' ? 'on' : 'off');
}
both of them fixed the problem but create security issue. Is there any other way that will help me with this kind of situation ?
Solution
Dennis Koch
Dennis Koch2w ago
I think ->trustProxies() is the right way. I think you can add your ngrok IP to limit this, but I don't think there is a high risk when you keep your ngrok URL to yourself.
Nick Ruddra
Nick RuddraOP2w ago
Ohhh Okey Thanks Brother.

Did you find this page helpful?