Pictures are now handeled correctly
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@ -412,8 +413,15 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
filename := fmt.Sprint(c.PicsDir, time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename)
|
||||
img, err := os.Create(filename)
|
||||
filename := fmt.Sprint(c.PicsDir, "/", time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename)
|
||||
absFilepath, err := filepath.Abs(filename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
img, err := os.Create(absFilepath)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
@ -428,6 +436,7 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc {
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/editor.html")
|
||||
template.Must(tmpl, err).ExecuteTemplate(w, "editor-images", fmt.Sprint(""))
|
||||
tmpl = template.Must(tmpl, err)
|
||||
tmpl.ExecuteTemplate(w, "editor-images", fmt.Sprint(""))
|
||||
}
|
||||
}
|
||||
|
22
cmd/view/images.go
Normal file
22
cmd/view/images.go
Normal file
@ -0,0 +1,22 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"streifling.com/jason/cpolis/cmd/control"
|
||||
)
|
||||
|
||||
func ServeImage(c *control.CliArgs, s *control.CookieStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
absFilepath, err := filepath.Abs(c.PicsDir)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user