delete zip after download
This commit is contained in:
parent
a5cf24366e
commit
53aece5e85
@ -23,15 +23,21 @@ public class DownloadZip extends AuthenticatedServlet {
|
||||
protected void doAuthenticatedGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
String zipFilename = req.getParameter(PARAMETER_FILENAME);
|
||||
File zipFile = new File(tempDir, zipFilename);
|
||||
if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) {
|
||||
resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename));
|
||||
resp.setContentType("application/zip");
|
||||
resp.setContentLengthLong(zipFile.length());
|
||||
FileInputStream fileInputStream = new FileInputStream(zipFile);
|
||||
fileInputStream.transferTo(resp.getOutputStream());
|
||||
fileInputStream.close();
|
||||
|
||||
if (zipFile.exists()) {
|
||||
if (zipFile.getParentFile().getCanonicalPath().equals(tempDir.getCanonicalPath())) {
|
||||
resp.addHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", zipFilename));
|
||||
resp.setContentType("application/zip");
|
||||
resp.setContentLengthLong(zipFile.length());
|
||||
FileInputStream fileInputStream = new FileInputStream(zipFile);
|
||||
fileInputStream.transferTo(resp.getOutputStream());
|
||||
fileInputStream.close();
|
||||
zipFile.delete();
|
||||
} else {
|
||||
throw new ServletException("-.-");
|
||||
}
|
||||
} else {
|
||||
throw new ServletException("-.-");
|
||||
resp.sendRedirect("/mavor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@
|
||||
<%@ page isELIgnored="false" %>
|
||||
<html>
|
||||
<body style="background-color:black; color:white">
|
||||
Output:<br/>
|
||||
<pre>${stdout}</pre><br/>
|
||||
File: <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/>
|
||||
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a>
|
||||
Download dependencies (Link only works once!): <a href="/mavor/download/zip?file=${zipFilename}">${zipFilename}</a><br/>
|
||||
<a href="/mavor/logout">logout</a> | <a href="/mavor">back</a><br/>
|
||||
Maven Output:<br/>
|
||||
<pre>${stdout}</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user