From 93d32309e876bccb98285a4b7504a5e16c5f156e Mon Sep 17 00:00:00 2001 From: "Sven.Schmalle" Date: Thu, 21 Nov 2019 11:57:54 +0100 Subject: [PATCH] Die Fotos werden jetzt nicht mehr im Browser angezeigt, sondern zum Download angeboten --- main.go | 19 +++++++++++++++++++ web/index.html | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 38413ea..87e5554 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func main() { router.HandleFunc("/folder/{foldername:.*}", getFolderContent).Methods("GET") router.HandleFunc("/qr/{qrlink:.*}", getQRCode).Methods("GET") router.HandleFunc("/thumb/{imgname:.*}", getThumbNail).Methods("GET") + router.HandleFunc("/imgdl/{imgname:.*}", getImageDownload).Methods("GET") router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(imgPath)))).Methods("GET") router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET") log.Fatal(http.ListenAndServe(":8000", router)) @@ -108,6 +109,24 @@ func getThumbNail(w http.ResponseWriter, r *http.Request) { } } +func getImageDownload(w http.ResponseWriter, r *http.Request) { + + // Variablen auswerten + params := mux.Vars(r) + pIMGName := params["imgname"] + + // Originaldatei öffnen, welche angefragt wird + src, err := imaging.Open(imgPath + "/" + pIMGName) + if err != nil { + log.Fatalf("failed to open image: %v", err) + } + + w.Header().Set("Content-Disposition", "attachment; filename=Fotobox_"+pIMGName) + + png.Encode(w, src) + +} + //-------------------------------------------------------------------------- // Hilfsfunktionen //-------------------------------------------------------------------------- diff --git a/web/index.html b/web/index.html index 2e266c7..ef96dd8 100644 --- a/web/index.html +++ b/web/index.html @@ -76,7 +76,7 @@ var ObjInhalt = content[i]; $("#Ordner").append(""+ ""+ - ""+ + ""+ ObjInhalt+"
"); } }