Set path to save files to Linux

Asked

Viewed 844 times

0

I have a Back-end done in Java where I get some files from the front and save them to a folder. This system ran on a server Windows with Tomcat but recently the same had to be migrated to Debian.

In the past I set the path to save the files as follows:

D:\\Auditoria\\uploads\\

Currently the path in which I want to save these files is:

/opt/tomcat/modulos/auditoria/uploads

As I show in the following image inserir a descrição da imagem aqui

Can I pass this path to save my files? Or is there another way?

Currently I create my file this way:

private final String DIRETORIO_UPLOAD_ARQUIVO = "D:\\Desenvolvimento\\Angular\\Auditoria\\uploads\\anexos\\";
File arquivo= new File(DIRETORIO_UPLOAD_ARQUIVO, file.getFileName());
  • Since the user that Tomcat is attached to (user that starts the service) has write access, I see no problem!

  • So at first glance just use the new URL.

  • You already tested that with the new URL?

  • @Jorgeb. I’m trying, it’s giving an Exception I’m trying to find the logs to analyze the errors

  • Must be somewhere in /var/log.

  • 1

    As commented by Nilsonuehara may be a matter of writing permission.

  • Go to the terminal and enter the command #sudo chmod 777 /opt/tomcat/modulos/auditoria/uploads this will release full recording permission, it is not a good practice to do this, but it is a solution.

Show 2 more comments

1 answer

1


Diegoaugusto is enough that you use the URL (path) of the destination directory. It is important to note only that the Tomcat runtime user (Tomcat daemon) must have run permission in this directory.

One way to do this is to put the final directory as property of the group in which the Tomcat user is.

On my computer (virtualbox) Tomcat is installed and run under tomcat7 user and tomcat7 group.

Refer to the username that is running Tomcat (do this as root)

# ps -ef | grep tomcat

the answer will be something like....

tomcat7   4001     1  0 11:50 ?        00:00:03 /usr/lib/jvm/default-java/bin/java -Djava.util.logging.config.file=/var/lib/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.....

which shows that Tomcat is running by the user tomcat7. It is this user who must have access permission in the directory you want. To give permission do (as root):

# chown -R tomcat7 /opt/tomcat/modulos/auditoria/uploads

I believe this is enough to solve your problem.

t+

Browser other questions tagged

You are not signed in. Login or sign up in order to post.