implemented file download

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-09-29 09:21:51 +02:00
parent ea8f564145
commit 1d90683b3e
2 changed files with 9 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.userService;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.files.Constants.CONFIG_DATABASE;
import static de.srsoftware.umbrella.files.Constants.CONFIG_FILESTORE;
import static java.net.HttpURLConnection.HTTP_OK;
public class FileModule extends BaseHandler implements FileService {
@@ -104,9 +105,14 @@ public class FileModule extends BaseHandler implements FileService {
private boolean getFile(HttpExchange ex, File file) throws IOException {
var headers = ex.getResponseHeaders();
//headers.add(CONTENT_TYPE, MIME_PDF);
var conn = file.toURI().toURL().openConnection();
var ct = conn.getContentType();
headers.add(CONTENT_TYPE, ct);
headers.add(CONTENT_DISPOSITION,"attachment; filename=\""+file.getName()+"\"");
return sendContent(ex,new FileInputStream(file));
ex.sendResponseHeaders(HTTP_OK, 0L);
new FileInputStream(file).transferTo(ex.getResponseBody());
return true;
}
private Map<String,Object> getDirectory(File file) throws IOException {