Skip to content

Commit

Permalink
show default image in case file dont exist
Browse files Browse the repository at this point in the history
  • Loading branch information
snirye committed Apr 18, 2020
1 parent 2f69fe5 commit 1bf48d2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/controller/images.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public images() {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filename = request.getPathInfo().substring(1);
String path=getServletContext().getInitParameter("upload_location")+filename;

System.out.println("Path is : "+path);

File file = new File(path, filename+".jpg");

System.out.println("file is : "+file.getPath());

if(!file.exists()) {
path=getServletContext().getInitParameter("upload_location")+"default";
file = new File(path, "default.jpg");
}
response.setHeader("Content-Type", getServletContext().getMimeType(filename));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + filename + "\"");
Files.copy(file.toPath(), response.getOutputStream());


}

/**
Expand Down

0 comments on commit 1bf48d2

Please sign in to comment.