F
Filamentā€¢12mo ago
abedrabaia

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ā€¢12mo 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ā€¢12mo ago
I did that and still same issue
ChesterS
ChesterSā€¢12mo 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ā€¢12mo ago
Did you config the APP_URL in .env file?
DrByte
DrByteā€¢12mo 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ā€¢12mo ago
Already did that Already did that Check the responce am getting an empty message , and it's already working locally
Matthew
Matthewā€¢12mo ago
Can you share the code of FileUpload component? @abedrabaia
abedrabaia
abedrabaiaOPā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo ago
I think if it was a middleware issue it won't work locally
Jamie Cee
Jamie Ceeā€¢12mo ago
You found a solution yet?
Patrick
Patrickā€¢12mo ago
and the apache log is empty? just to make sure
toeknee
toekneeā€¢12mo 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ā€¢12mo ago
See the last post. FYI most people use nginx and nice pre-built CI/CD setups for laravel
Jamie Cee
Jamie Ceeā€¢12mo ago
That hasnt solved it for me
Patrick
Patrickā€¢12mo 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ā€¢12mo 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ā€¢12mo ago
No description
Patrick
Patrickā€¢12mo ago
can you comment out this line and see if that is the issue
Patrick
Patrickā€¢12mo ago
No description
Patrick
Patrickā€¢12mo ago
these 2 files
Jamie Cee
Jamie Ceeā€¢12mo ago
So that uploads, but when I go to save the form:
No description
Patrick
Patrickā€¢12mo ago
okay but no more 401 now
Jamie Cee
Jamie Ceeā€¢12mo ago
No, but I cant leave the vendors edited like that?
Patrick
Patrickā€¢12mo ago
no u canbt but the issue is known now not that is helps no fix šŸ˜¦
Jamie Cee
Jamie Ceeā€¢12mo ago
Ah šŸ¤£ Was expecting you to know the root of all my problems šŸ˜‰
Patrick
Patrickā€¢12mo ago
are you using cloudflare for ssl or proxy
Jamie Cee
Jamie Ceeā€¢12mo ago
Not sure, I dont setup our servers at work šŸ¤£
Patrick
Patrickā€¢12mo ago
i can check do you have an url ?
Jamie Cee
Jamie Ceeā€¢12mo ago
Are you able to guide me how to check? I dont think Im allowed to share the URL
Patrick
Patrickā€¢12mo 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ā€¢12mo ago
yea just throw it in here and look where the nameservers are pointing to
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
yea my guess is that they proxy the request and that fucks it up, no valid signature šŸ˜¦
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
sorry what do you mean exactly
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
yea that would probably fix it have you tried adding * to the proxies config btw
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
no thats in filament let me look it up for you sec
Patrick
Patrickā€¢12mo ago
No description
Solution
Patrick
Patrickā€¢12mo ago
so like this
No description
Patrick
Patrickā€¢12mo ago
not sure if it helps but worth a try
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
did u still have that line commented out? šŸ˜› in the core file
Jamie Cee
Jamie Ceeā€¢12mo ago
Nah, I undone that, It may be something to do with my code, 2 mins
Patrick
Patrickā€¢12mo ago
hehe alright back in a few mins smoke break
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
yea thats good proper solution
Jamie Cee
Jamie Ceeā€¢12mo ago
Are you able to explain what its done? (Im just trying to learn now) Im assuming allow anything basically
Patrick
Patrickā€¢12mo 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ā€¢12mo 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ā€¢12mo 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ā€¢12mo ago
THats alright then, thank you šŸ˜„
Patrick
Patrickā€¢12mo ago
yea we should give credit to @toeknee he pointed to the stack overflow šŸ˜›
toeknee
toekneeā€¢12mo ago
Most welcomes, ideally you shouldn't use a wildcard šŸ˜‰
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
oh dude im in the business for 15 years, i still have daily mysteries that will never change
toeknee
toekneeā€¢12mo ago
Yeah, raise it as a ticket upstream and they will advise accordingly šŸ˜‰ But we are all learning daily!
Jamie Cee
Jamie Ceeā€¢12mo 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ā€¢12mo ago
your welcome! have a nice day dudes
Want results from more Discord servers?
Add your server