Processing files uploaded to the server, but cannot be accessed via url. It can be accessed after modifying the file permissions. How to solve it?

A recent project requires shared storage of files. There are currently three nodes (for example, 99, 97, 98). The problem encountered is that files uploaded on 97 cannot be downloaded on 98 and 99.

The reason is because of the permission problem, that is, after modifying the file permissions, other nodes can access it. I thought of this step.

   I have two ideas. The first one is why the files uploaded by 98 and 99 can be downloaded directly from each other, but only the 97 node cannot be downloaded. Can 97 be made the same as 98 and 99? The second one is , use java code to modify the file permissions, which can also achieve the effect.

   With two ideas, let’s first think about using the first one. Why is 97 different from others? The reason is that the file uploaded by each node generates the corresponding uid and gid. These two ids are the user’s id and group respectively. ID, 99 and 98 generate the same uid, but 97 generates a different uid. Why does this happen? Due to time constraints, I chose the second method.

   The second way is to modify the uploaded attachment permissions through java code, such as the following code

          Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); perms.add(PosixFilePermission.OWNER_READ); //Set the owner's read permission  

perms.add(PosixFilePermission.OWNER_WRITE); //Set the owner's write permission  

perms.add(PosixFilePermission.OWNER_EXECUTE); //Set the owner's execution permission perms.add(PosixFilePermission.GROUP_READ); //Set the group's read permission  

perms.add(PosixFilePermission.GROUP_EXECUTE); //Set the group's execution permissions  

perms.add(PosixFilePermission.OTHERS_READ); //Set other read permissions perms.add(PosixFilePermission.OTHERS_EXECUTE); //Set other execution permissions

//Main methods to modify file permissions

Files.setPosixFilePermissions(pathDest, perms); //Modify file permissions

Redeploy the code and the problem is solved. The first way is to study it when you have time. I hope it can help you.

Guess you like

Origin blog.csdn.net/y15201653575/article/details/86542775