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.
I found the problem - it was my file path string
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:
And now it's working.