1

So to not repeat myself too much, please refer to serve static image along side 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

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.

Community
  • 1
  • 1
Pouton Gerald
  • 1,625
  • 22
  • 32

2 Answers2

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.

Striker
  • 339
  • 1
  • 3
  • 13
  • I have no idea what you mean. Recall: I can reach the file thru the browser but not from within the same server and yet the folder in question is inside the war directory. – Pouton Gerald May 13 '13 at 00:38
  • What's the URL you're using to get to the file in your browser? Also, what OS are you running this on and what app server? – Striker May 13 '13 at 00:58
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.

Dave W. Smith
  • 24,318
  • 4
  • 40
  • 46
  • On localhost it was easy to find the path to my static files. Now that I have deployed, it's not at `myapi@appspot.gserviceaccount.com/images/willsmith.jpg` as I would expect. Any ideas? – Pouton Gerald May 13 '13 at 05:06