So to not repeat myself too much, please refer to serve static image along side java google-enpoint api.
所以不要重复太多,请参考java google-enpoint api旁边的静态图片。
As you can see from the referenced link, I am able to view the image through the url. However, when I am trying to read filenames using similar code to
从引用的链接可以看出,我可以通过url查看图像。但是,当我尝试使用类似的代码读取文件名时
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
I get a security exception
我得到一个安全例外
java.security.AccessControlException: access denied ("java.io.FilePermission" "/myImages" "read")
Does anyone know the fix? How come the call thru the browser show the image and yet a call from within the server itself throws an exception? I find that strange.
有谁知道修复?为什么通过浏览器的调用显示图像,然而来自服务器本身的调用会引发异常?我觉得很奇怪。
2 个解决方案
#1
1
If you've configured a file as a "static" resource, it'll be served up by a separate pool of servers that are optimized for serving static content. A consequence is that the file isn't available to be opened from your app. "resource" files are available for the app to open and read.
如果您已将文件配置为“静态”资源,则它将由为服务静态内容而优化的单独服务器池提供。结果是该文件无法从您的应用程序打开。 “资源”文件可供应用打开和阅读。
That's documented here.
这是在这里记录的。
You'll need to use a relative path when opening a resource. You've shown an absolute path above.
打开资源时,您需要使用相对路径。你已经展示了上面的绝对路径。
#2
1
If the server is running as a service, make sure that service has permissions to the folder and files you're trying to read.
如果服务器作为服务运行,请确保该服务对您尝试读取的文件夹和文件具有权限。
#1
1
If you've configured a file as a "static" resource, it'll be served up by a separate pool of servers that are optimized for serving static content. A consequence is that the file isn't available to be opened from your app. "resource" files are available for the app to open and read.
如果您已将文件配置为“静态”资源,则它将由为服务静态内容而优化的单独服务器池提供。结果是该文件无法从您的应用程序打开。 “资源”文件可供应用打开和阅读。
That's documented here.
这是在这里记录的。
You'll need to use a relative path when opening a resource. You've shown an absolute path above.
打开资源时,您需要使用相对路径。你已经展示了上面的绝对路径。
#2
1
If the server is running as a service, make sure that service has permissions to the folder and files you're trying to read.
如果服务器作为服务运行,请确保该服务对您尝试读取的文件夹和文件具有权限。