我有一个应用程序,可以将上传的文件移动到驱动器中的某个位置,如下所示:
def storagePathDirectory = new File(destinationPath)
if(!storagePathDirectory.exists()) {
log.info("Storage Path Directory does not exist. Creating a new directory: ${storagePathDirectory.toString()} ...")
if (storagePathDirectory.mkdirs()){
log.info("Successfully created: ${storagePathDirectory.toString()}")
} else {
log.info("Failed to create: ${storagePathDirectory.toString()}...")
}
}
我想保存在
/usr/local/something/something
下。如果该应用尝试将文件移动到不受限制的文件夹/home/user/something
中,则效果很好。我是否需要为我的应用设置权限,以便它可以在/usr/
下写入文件?我该如何使用grails?
最佳答案
没错,您需要向主机OS上的目标方向授予权限。这些权限应尽可能严格。允许对正在运行哪个Tomcat(或用于运行WAR的任何容器)的帐户进行读写。
您将要遇到的问题通常是/ usr /,不允许该帐户访问它。因此,您的应用程序本身无法更改权限。这将必须由服务器的管理员来完成。
同样,对您的权限尽可能严格。不要为所有人简单地使用chmod -R 777。请至少考虑770。
关于grails - 如果我想使用我的grails应用程序将上传的文件保存在 '/usr/local'中,我是否需要授予权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24722083/