Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
- HandlerResponse for downloads; user file name
  • Loading branch information
autumoswitzerland committed Oct 6, 2024
1 parent ebae310 commit aaf6575
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Binary file not shown.
6 changes: 5 additions & 1 deletion src/main/java/ch/autumo/beetroot/handler/BaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,11 @@ public final Response get(UriResource uriResource, Map<String, String> urlParams
if (!file.exists())
throw new FileNotFoundException("File '"+file.getName()+"' doesn't exist (Download)!");
final Response downloadResponse = Response.newFixedLengthResponse(getStatus(), mime, new FileInputStream(file), file.length());
downloadResponse.addHeader("Content-disposition", "attachment; filename=" +file.getName());
String fName = response.getDownloadFileName();
if (fName == null || fName.length() == 0) {
fName = file.getName();
}
downloadResponse.addHeader("Content-disposition", "attachment; filename=" + fName);
return downloadResponse;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ch/autumo/beetroot/handler/HandlerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class HandlerResponse {
private Exception exception = null;
private Object object = null;
private File downloadFile = null;
private String downloadFileName = null;
private String downloadFileMimeType = null;

private Response httpResponse = null;
Expand Down Expand Up @@ -207,6 +208,14 @@ public void setDownloadFile(File downloadFile) {
this.downloadFile = downloadFile;
}

public String getDownloadFileName() {
return downloadFileName;
}

public void setDownloadFileName(String downloadFileName) {
this.downloadFileName = downloadFileName;
}

public String getDownloadFileMimeType() {
return downloadFileMimeType;
}
Expand Down

0 comments on commit aaf6575

Please sign in to comment.