Skip to content
Snippets Groups Projects
Commit 987c3ff5 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Add images to database associated with owner

parent 90ecad56
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"encoding/base64" "encoding/base64"
"crypto/rand" "crypto/rand"
"time" "time"
"database/sql"
) )
func writeBody(reader io.ReadCloser, path string) error { func writeBody(reader io.ReadCloser, path string) error {
...@@ -102,17 +103,16 @@ func main() { ...@@ -102,17 +103,16 @@ func main() {
Password: config.Redis.Password, Password: config.Redis.Password,
}) })
//db, err := sql.Open(config.Database.Format, config.Database.Url) db, err := sql.Open(config.Database.Format, config.Database.Url)
//if err != nil { if err != nil {
//panic(err) panic(err)
//} }
staticServer := http.FileServer(http.Dir("static/")) staticServer := http.FileServer(http.Dir("static/"))
imageServer := http.FileServer(http.Dir(config.TargetFolder)) imageServer := http.FileServer(http.Dir(config.TargetFolder))
http.HandleFunc("/upload/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/upload/", func(w http.ResponseWriter, r *http.Request) {
printHeaders(r) user := r.Header.Get("X-Auth-Id")
if r.Method == "POST" { if r.Method == "POST" {
r.ParseMultipartForm(32 << 20) r.ParseMultipartForm(32 << 20)
file, _, err := r.FormFile("file") file, _, err := r.FormFile("file")
...@@ -126,6 +126,13 @@ func main() { ...@@ -126,6 +126,13 @@ func main() {
return return
} }
result, err := db.Exec("INSERT INTO images (id, owner) VALUES ($1, $2)", image.Id, user)
if err != nil {
panic(err)
}
println(result)
fmt.Printf("Created task %s at %d\n", image.Id, time.Now().Unix()) fmt.Printf("Created task %s at %d\n", image.Id, time.Now().Unix())
data, err := json.Marshal(image) data, err := json.Marshal(image)
...@@ -186,7 +193,7 @@ func main() { ...@@ -186,7 +193,7 @@ func main() {
staticServer.ServeHTTP(w, r) staticServer.ServeHTTP(w, r)
}) })
err := http.ListenAndServe(":8080", nil) err = http.ListenAndServe(":8080", nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment