第一种,直接显示图片在页面上
func DownloadHandler(w http.ResponseWriter, r *http.Request) {
//imgpath := "C:\\Users\\cixu\\Pictures\\"+mux.Vars(r)["imgid"]
imgpath := "C:\\Users\\cixu\\Pictures\\1.jpg"
//imgpath := "./uploads/"+mux.Vars(r)["imgid"]
http.ServeFile(w, r, imgpath)
}
第二种,把图片信息传过去(json)
func DownloadHandler(w http.ResponseWriter, r *http.Request) {
imgs_dir = "C:\\Users\\cixu\\Desktop\\1\\"
w.Header().Set("Content-Type", "image/jpg")
file, err := ioutil.ReadFile(imgpath)
if err != nil {
fmt.Fprintf(w,"查无此图片")
return
}
File,_:= json.Marshal(file)
w.Write(File)
}
1033

被折叠的 条评论
为什么被折叠?



