Die Fotos werden jetzt nicht mehr im Browser angezeigt, sondern zum Download angeboten

This commit is contained in:
Sven.Schmalle 2019-11-21 11:57:54 +01:00
parent 2e47fbde64
commit 93d32309e8
2 changed files with 20 additions and 1 deletions

19
main.go
View File

@ -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
//--------------------------------------------------------------------------

View File

@ -76,7 +76,7 @@
var ObjInhalt = content[i];
$("#Ordner").append(""+
"<img src=\""+ServerAPI+"/thumb/"+folder+"/"+ObjInhalt+"\" width=200>"+
"<a href=\""+ServerAPI+"/img/"+folder+"/"+ObjInhalt+"\">"+
"<a href=\""+ServerAPI+"/imgdl/"+folder+"/"+ObjInhalt+"\">"+
ObjInhalt+"</a><hr>");
}
}