Image upload error on production server

Upload image working fine locally but something is wrong when deploying to production server, I checked laravel log file but there were nothing, also checked the file permission and same issue Any one can help me fix the issue ?
No description
No description
No description
No description
Solution:
so like this
No description
Jump to solution
67 Replies
Moudjames23
Moudjames23•2y ago
Hello, in your .env file you must change the value of APP_URL=http://127.0.0.1 to your correct domain name and make sure to execute this command:
php artisan storage:link
php artisan storage:link
abedrabaia
abedrabaiaOP•2y ago
I did that and still same issue
ChesterS
ChesterS•2y ago
you need to make sure the permissions on the folder are correct too. I'm not sure what the exact settings are but you can try 655 or something similar
LeandroFerreira
LeandroFerreira•2y ago
Did you config the APP_URL in .env file?
DrByte
DrByte•2y ago
It says you're getting a 401 Unauthorized error. That means your application says you don't have permission to do what it's trying to do.
No description
abedrabaia
abedrabaiaOP•2y ago
Already did that Already did that Check the responce am getting an empty message , and it's already working locally
Matthew
Matthew•2y ago
Can you share the code of FileUpload component? @abedrabaia
abedrabaia
abedrabaiaOP•2y ago
Here is the resource file And it's working locally fine and there is no issues in Laravel log on the server
abedrabaia
abedrabaiaOP•2y ago
I think it's releated to Livewire upload since am not getting an error from filament , it started to happen when SSL certificate was added to the serve ! and i can't understand what causing it since it returns an empty message
Patrick
Patrick•2y ago
i think the issue is pretty clear its a permission issue on your production environment i would check the server logs instead of the laravel logs
abedrabaia
abedrabaiaOP•2y ago
If it was a file persmession issue I would found an error in laravel log I thing it didn't even reach the upload function ! It was rejected before and can't find why
Patrick
Patrick•2y ago
yea thats why u should look at the server log are you using something to manage your hosting? Plesk panel or some sort? if your server is denying the request, you won't find it in laravel it doesn't reach it so no use to look tehre
abedrabaia
abedrabaiaOP•2y ago
@Patrick1989 We are using an Ubuntu 20 server with Apache2 I managed to upload files using native upload method but the Livewire upload is not working
Patrick
Patrick•2y ago
and what's the log message for the 403? or 401
/var/log/apache2/error.log
/var/log/apache2/error.log
should be in that file and make sure theres not some middleware messing things up šŸ˜› oh wait that response in your screenshot yea nvm its coming from livewire you sure you have no like auth middleware hanging in the middle?
Jamie Cee
Jamie Cee•2y ago
Im getting same issue, nothing in logs, perms 777, works locally. Have no issue normally uploading images to this server, only until filament was implemented, and the File component
abedrabaia
abedrabaiaOP•2y ago
I think if it was a middleware issue it won't work locally
Jamie Cee
Jamie Cee•2y ago
You found a solution yet?
Patrick
Patrick•2y ago
and the apache log is empty? just to make sure
toeknee
toeknee•2y ago
Stack Overflow
Livewire WithFileUpload 401 with url's not matching so failing sign...
I have a livewire file uploader on a project. When you select a file it says The uploads failed to upload. The firefox dev toolbox says it is a 401 error. I investigated further and found via https://
toeknee
toeknee•2y ago
See the last post. FYI most people use nginx and nice pre-built CI/CD setups for laravel
Jamie Cee
Jamie Cee•2y ago
That hasnt solved it for me
Patrick
Patrick•2y ago
in your code do you use the preview url? if so, does it start working when you comment it out??
Jamie Cee
Jamie Cee•2y ago
Fieldset::make('Offer Image')
->schema([
Forms\Components\FileUpload::make('avatar')
->image()
->disk('public')
->directory('offers')
->imageEditor()
->imageEditorMode(2),
]),
Fieldset::make('Offer Image')
->schema([
Forms\Components\FileUpload::make('avatar')
->image()
->disk('public')
->directory('offers')
->imageEditor()
->imageEditorMode(2),
]),
Thats all I have
Patrick
Patrick•2y ago
No description
Patrick
Patrick•2y ago
can you comment out this line and see if that is the issue
Patrick
Patrick•2y ago
No description
Patrick
Patrick•2y ago
these 2 files
Jamie Cee
Jamie Cee•2y ago
So that uploads, but when I go to save the form:
No description
Patrick
Patrick•2y ago
okay but no more 401 now
Jamie Cee
Jamie Cee•2y ago
No, but I cant leave the vendors edited like that?
Patrick
Patrick•2y ago
no u canbt but the issue is known now not that is helps no fix 😦
Jamie Cee
Jamie Cee•2y ago
Ah 🤣 Was expecting you to know the root of all my problems šŸ˜‰
Patrick
Patrick•2y ago
are you using cloudflare for ssl or proxy
Jamie Cee
Jamie Cee•2y ago
Not sure, I dont setup our servers at work 🤣
Patrick
Patrick•2y ago
i can check do you have an url ?
Jamie Cee
Jamie Cee•2y ago
Are you able to guide me how to check? I dont think Im allowed to share the URL
Patrick
Patrick•2y ago
Whois Lookup, Domain Availability & IP Search - DomainTools
Research domain ownership with Whois Lookup: Get ownership info, IP address history, rank, traffic, SEO & more. Find available domains & domains for sale.
Patrick
Patrick•2y ago
yea just throw it in here and look where the nameservers are pointing to
Jamie Cee
Jamie Cee•2y ago
ame Server: ns20.digicertdns.com
Name Server: ns21.digicertdns.com
Name Server: ns22.digicertdns.com
Name Server: ns23.digicertdns.net
ame Server: ns20.digicertdns.com
Name Server: ns21.digicertdns.com
Name Server: ns22.digicertdns.com
Name Server: ns23.digicertdns.net
Patrick
Patrick•2y ago
yea my guess is that they proxy the request and that fucks it up, no valid signature 😦
Jamie Cee
Jamie Cee•2y ago
Ah, so could be just how we have our staging servers setup rather than a constant problem? So a valid prod URL may be fine?
Patrick
Patrick•2y ago
sorry what do you mean exactly
Jamie Cee
Jamie Cee•2y ago
So the no valid signature thing, is that not just because of our staging server? as we have many sub domains with different projects on. Where if they then go to prod and have a proper SSL, or am I just misunderstanding things?
Patrick
Patrick•2y ago
yea that would probably fix it have you tried adding * to the proxies config btw
Jamie Cee
Jamie Cee•2y ago
I have not, assuming thats in the nginx config? I haven't touched that, it was setup by a colleague for all projects we use
Patrick
Patrick•2y ago
no thats in filament let me look it up for you sec
Patrick
Patrick•2y ago
No description
Solution
Patrick
Patrick•2y ago
so like this
No description
Patrick
Patrick•2y ago
not sure if it helps but worth a try
Jamie Cee
Jamie Cee•2y ago
That did actually do something, just got this error now, So it may allow the upload, but dont think its saving to the DB?
No description
Patrick
Patrick•2y ago
did u still have that line commented out? šŸ˜› in the core file
Jamie Cee
Jamie Cee•2y ago
Nah, I undone that, It may be something to do with my code, 2 mins
Patrick
Patrick•2y ago
hehe alright back in a few mins smoke break
Jamie Cee
Jamie Cee•2y ago
Feel like I need to start with how much stress I've been getting lately 🤣 But nah, that works, the issue above was due to a check I have, in which trying to remove an avatar (I replace when upload) that didn't exist, I need to do a null check. So is this advised or is this bad?
Patrick
Patrick•2y ago
yea thats good proper solution
Jamie Cee
Jamie Cee•2y ago
Are you able to explain what its done? (Im just trying to learn now) Im assuming allow anything basically
Patrick
Patrick•2y ago
Setting trusted proxies in Laravel to * (a wildcard) solves your issue because it instructs Laravel to trust all proxies regarding the headers they set. When a Laravel application is behind a reverse proxy (like Cloudflare), certain request attributes (such as the scheme and the client IP) might be modified by the proxy. gpt šŸ˜›
Jamie Cee
Jamie Cee•2y ago
Fair point haha, but sometimes gpt is a bit unreliable also 🤣 So is there anything to keep an eye out that should probably be blocked but will be bypassed because of this?
Patrick
Patrick•2y ago
if you know the exact host u can use that instead of a wildcard but tbh i'm not expecting any issues coming from this
Jamie Cee
Jamie Cee•2y ago
THats alright then, thank you šŸ˜„
Patrick
Patrick•2y ago
yea we should give credit to @toeknee he pointed to the stack overflow šŸ˜›
toeknee
toeknee•2y ago
Most welcomes, ideally you shouldn't use a wildcard šŸ˜‰
Jamie Cee
Jamie Cee•2y ago
Yeah, but hopefully it can be changed by something my other teams can change. Im still a junior so im clueless with this 🤣
Patrick
Patrick•2y ago
oh dude im in the business for 15 years, i still have daily mysteries that will never change
toeknee
toeknee•2y ago
Yeah, raise it as a ticket upstream and they will advise accordingly šŸ˜‰ But we are all learning daily!
Jamie Cee
Jamie Cee•2y ago
Thankfully my team is only me and 2 other devs, and we all work closely, so they may know. Just they're busy currently so haven't had time to ask. I claim just under 3 years, I did do uni for 3 years, but it wasnt all php and it was outdated, so job wise, under 3 years But anyway, thanks guys.
Patrick
Patrick•2y ago
your welcome! have a nice day dudes

Did you find this page helpful?