Sitebricks file download service throws AccessControlException - access denied

69 Views Asked by At

I need to make a file available for download from a certain URL on my server(It's a google app angine project). Here is what I use:

@At("/api/download")
@Service
public class ZipDownloadService {

  @Get
  public Reply<?> downloadZip() throws IOException, ServletException {

    try (FileInputStream stream = new FileInputStream("/assets/zip/my_file.zip")) {
      final byte[] bytes = IOUtils.toByteArray(stream);
      return Reply.with(bytes).type("application/octet-stream").as(Raw.class);
    }
  }
}

The zip file is stored in the web directory of my project and the file has read permissions for everyone, but when I go to the url I always get the AccessControlException.

1

There are 1 best solutions below

0
On

I found the problem - it was my file path string

"/assets/zip/my_file.zip"

With the slash at the beginning the path was relative to the file system, not the server root. And that is why access is denied - server does not have permission to read the root of the file system and moreover, the file cannot be found at all on that path.

So the solution - remove the leading slash:

"assets/zip/my_file.zip"

And now it's working.