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.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.files.Constants.CONFIG_DATABASE; import static de.srsoftware.umbrella.files.Constants.CONFIG_DATABASE;
import static de.srsoftware.umbrella.files.Constants.CONFIG_FILESTORE; import static de.srsoftware.umbrella.files.Constants.CONFIG_FILESTORE;
import static java.net.HttpURLConnection.HTTP_OK;
public class FileModule extends BaseHandler implements FileService { 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 { private boolean getFile(HttpExchange ex, File file) throws IOException {
var headers = ex.getResponseHeaders(); 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()+"\""); 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 { private Map<String,Object> getDirectory(File file) throws IOException {

View File

@@ -67,7 +67,7 @@
{#each Object.entries(children.files) as [k,v]} {#each Object.entries(children.files) as [k,v]}
<li class="file"> <li class="file">
<span class="symbol"></span> <span class="symbol"></span>
<a href={'/files'+k} {onclick}>{v}</a> <a href={'/api/files'+k} target="_blank">{v}</a>
</li> </li>
{/each} {/each}
{/if} {/if}