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+"
"); } }