Summary
I’m not able to upload any images.
Steps to reproduce
If I try to upload a profile picture I get the error message “Couldn’t upload profile image.”
The same applies if I try to upload an image in a post (without the error message).
Expected behavior
No error message 
Observed behavior
Here is what is written in the log:
{“timestamp”:“2023-02-18 21:45:21.934 Z”,“level”:“error”,“msg”:“Couldn’t upload profile image.”,“caller”:“web/context.go:117”,“path”:“/api/v4/users/r9jbasyaciyefbfp6shf5mc8cy/image”,“request_id”:“jdqsutbyn7rx3dw6huar11mctr”,“ip_addr”:“127.0.0.1”,“user_id”:“r9jbasyaciyefbfp6shf5mc8cy”,“method”:“POST”,“err_where”:“SetProfileImage”,“http_code”:500,“error”:“SetProfileImage: Couldn’t upload profile image., WriteFile: Unable to write the file., unable to create the directory /var/opt/mattermost/data/users/r9jbasyaciyefbfp6shf5mc8cy for the file /var/opt/mattermost/data/users/r9jbasyaciyefbfp6shf5mc8cy/profile.png: mkdir /var/opt/mattermost/data: permission denied”}
{“timestamp”:“2023-02-18 21:45:21.989 Z”,“level”:“error”,“msg”:“Unable to write the file.”,“caller”:“web/context.go:117”,“path”:“/api/v4/users/r9jbasyaciyefbfp6shf5mc8cy/image”,“request_id”:“4f7mundbr3dz8xwsrsuf79d6ww”,“ip_addr”:“127.0.0.1”,“user_id”:“r9jbasyaciyefbfp6shf5mc8cy”,“method”:“GET”,“err_where”:“WriteFile”,“http_code”:500,“error”:“WriteFile: Unable to write the file., unable to create the directory /var/opt/mattermost/data/users/r9jbasyaciyefbfp6shf5mc8cy for the file /var/opt/mattermost/data/users/r9jbasyaciyefbfp6shf5mc8cy/profile.png: mkdir /var/opt/mattermost/data: permission denied”}
I deleted the whole server instance and did a complete re-install. Now it is working 
Hi @scrumphony and welcome to the Mattermost forums!
Sorry for my late reply, but the error message indicates that the file permissions were wrong, so maybe upon your first try, you forgot to run the necessary chown
command on the /var/opt/mattermost
directory.
@lucyclhill can you check that on your system, since you seem to have the same problem? If your Mattermost application is being run with user mattermost
(f.ex.), then the directory and all the files below it also need to be owned by this user. The default installation suggests to use /opt/mattermost
as the base directory as well as mattermost
for the system account, so if you changed it, please do also change it in the following command:
chown -R mattermost: /opt/mattermost
This should fix all issues related to wrong filesystem permissions.
Hi @agriesser
Thank you for the reply. This was the strange thing: the file permissions were correct. I even did a chmod -r 777 on the directory, but that didn’t help either.
Now, that I installed everything from scratch everything is running smoothly and my community enjoys using Mattermost 
Very interesting - sorry for not having replied earlier, would have been an interesting debugcase. Anyways, I’m marking this as resolved now.
hi there - I’m not a tech / IT person so I’m afraid I don’t know what this request means / what I’m meant to do… can you give itemised instructions on how I do this?
@lucyclhill can you check that on your system, since you seem to have the same problem? If your Mattermost application is being run with user mattermost
(f.ex.), then the directory and all the files below it also need to be owned by this user. The default installation suggests to use /opt/mattermost
as the base directory as well as mattermost
for the system account, so if you changed it, please do also change it in the following command:
I did send the command you need to run right after the text part you quoted, but it’s hard for me to give you detailed itemised instructions without knowing anything about your deployment. One of the good things with Mattermost is, that you can install it in many different ways and it integrates into many different applications and this is also (from a support point of view) a very challenging situation, since the same fix needs to be carried out differently depending on the context.
What deployment method did you use? Docker? Binary? Omnibus? Gitlab-integrated? etc.