Die Fotos werden jetzt nicht mehr im Browser angezeigt, sondern zum Download angeboten
This commit is contained in:
parent
2e47fbde64
commit
93d32309e8
19
main.go
19
main.go
@ -26,6 +26,7 @@ func main() {
|
|||||||
router.HandleFunc("/folder/{foldername:.*}", getFolderContent).Methods("GET")
|
router.HandleFunc("/folder/{foldername:.*}", getFolderContent).Methods("GET")
|
||||||
router.HandleFunc("/qr/{qrlink:.*}", getQRCode).Methods("GET")
|
router.HandleFunc("/qr/{qrlink:.*}", getQRCode).Methods("GET")
|
||||||
router.HandleFunc("/thumb/{imgname:.*}", getThumbNail).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("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(imgPath)))).Methods("GET")
|
||||||
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
||||||
log.Fatal(http.ListenAndServe(":8000", router))
|
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
|
// Hilfsfunktionen
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
var ObjInhalt = content[i];
|
var ObjInhalt = content[i];
|
||||||
$("#Ordner").append(""+
|
$("#Ordner").append(""+
|
||||||
"<img src=\""+ServerAPI+"/thumb/"+folder+"/"+ObjInhalt+"\" width=200>"+
|
"<img src=\""+ServerAPI+"/thumb/"+folder+"/"+ObjInhalt+"\" width=200>"+
|
||||||
"<a href=\""+ServerAPI+"/img/"+folder+"/"+ObjInhalt+"\">"+
|
"<a href=\""+ServerAPI+"/imgdl/"+folder+"/"+ObjInhalt+"\">"+
|
||||||
ObjInhalt+"</a><hr>");
|
ObjInhalt+"</a><hr>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user