F
Filament3mo ago
Jure

FileUpload 401 (Unauthorized)

When I am trying to save an image I get "Error during upload" with "The data.field.image_id failed to upload." I have Laravel installed on a path that is "domian.com/backend". So far everything else works fine. What is wrong? How can I fix this? Thank you for all your help!
No description
No description
No description
14 Replies
awcodes
awcodes3mo ago
Are you on shared hosting? Seems like a permission issue on the server for the tmp-livewire directory in storage.
Jure
Jure3mo ago
No, Digitsl ocean own droplet...
awcodes
awcodes3mo ago
Hmm. Still feels like a directory permissions issue to me.
Jure
Jure3mo ago
Permissions look ok.
No description
awcodes
awcodes3mo ago
What are the permissions for storage/tmp-livewire It could be that you need to create the directory too. Your server might not be able to create it if it doesn’t exist. I would expect it all to be fine using forge though. Definitely I server config issue though, but surprised since you’re using forge.
Jure
Jure3mo ago
There is no such folder. I'll try to make one and tets again in the morning. Thank you for now, I'll let you know how that works.
Jure
Jure2mo ago
The folder storage/app/livewire-tmp is never created. Evan if I add a folder error is exactly the same. So I would guess that the path before the livewire-tmp is not getting passed correctly. As I mentioned earlier I have a base URL on path example.com/backend and I had problems with routing before so I had to add code from the screenshot to routes/web.php where app.be_path='backend': Is it possible that another route is needed for saving to livewire-tmp
No description
awcodes
awcodes2mo ago
Do some research on server config for running laravel in a subdirectory. I think that will solve all your problems. Then you won’t need to worry about any of the routing.
Jure
Jure2mo ago
I have found a solution how to setup the NGINX server for Laravel to work in a subfolder. Thank you again for your guidance. https://codewithsusan.com/notes/run-laravel-from-subdirectory-on-nginx
gustavo.dev
gustavo.dev2mo ago
Hi!
gustavo.dev
gustavo.dev2mo ago
The exact same thing happened to me in a production environment.
No description
gustavo.dev
gustavo.dev2mo ago
Could you please help me
Jure
Jure5w ago
Hi, the problem is that livewire.js is loaded from the wrong location. Our solution was to write a redirect on the NGNIX config file to cath livewire.js and load it from the right path. We did it like this:
server {

OTHER CONFIG ...

location /<FOLDER> {
alias /home/www/public<FOLDER>/public;
try_files $uri $uri/ @nested;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param DOCUMENT_ROOT /home/www/public<FOLDER>/public;
}
}

location @nested {
rewrite /<FOLDER>/(.*)$ /<FOLDER>/index.php?/$1 last;
}

location /<FOLDER>/livewire/livewire.js {
alias /home/www/public/<FOLDER>/vendor/livewire/livewire/dist/livewire.js;
}

... REMAINING CONFIG
}
server {

OTHER CONFIG ...

location /<FOLDER> {
alias /home/www/public<FOLDER>/public;
try_files $uri $uri/ @nested;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param DOCUMENT_ROOT /home/www/public<FOLDER>/public;
}
}

location @nested {
rewrite /<FOLDER>/(.*)$ /<FOLDER>/index.php?/$1 last;
}

location /<FOLDER>/livewire/livewire.js {
alias /home/www/public/<FOLDER>/vendor/livewire/livewire/dist/livewire.js;
}

... REMAINING CONFIG
}
This is inserted right after defining the root folder, certificates, headers, and index. I hope you can solve your problem with this.
Ayman Alhattami
In Laravel 11, this worked with me
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
})
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
})
Want results from more Discord servers?
Add your server