Skip to content
Snippets Groups Projects
Commit 6ab5220d authored by gbe's avatar gbe
Browse files

Allow updating the image in the details view

parent ad96e662
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,28 @@ func (h Handler) detailsPost(w http.ResponseWriter, r *http.Request) {
v.Name = name
v.Rating = rating
err = r.ParseMultipartForm(16 * 1024 * 1024)
if err != nil {
httpError(w, "can't parse multipart form data", err, http.StatusInternalServerError)
return
}
// See if there's an image file uploaded
if len(r.MultipartForm.File["picture"]) != 0 {
picFile, picHdr, err := r.FormFile("picture")
if err != nil {
httpError(w, "can't open picture file", err, http.StatusInternalServerError)
return
}
defer picFile.Close()
err = v.AddPicture(picFile, picHdr.Header.Get("Content-Type"))
if err != nil {
httpError(w, "can't load picture", err, http.StatusBadRequest)
return
}
}
err = v.Store(r.Context(), h.db, Update)
if err != nil {
httpError(w, "can't store wine", err, http.StatusInternalServerError)
......
......@@ -3,7 +3,7 @@
{{ define "title" }}Details for {{ .Wine.Name }}{{ end }}
{{ define "content" }}
<form class="pure-form pure-form-aligned" method="POST">
<form class="pure-form pure-form-aligned" enctype="multipart/form-data" method="POST">
<header class="pure-u-1">
<div class="maxwidth box">
<a class="pure-button" href="/">Back</a>
......@@ -29,6 +29,12 @@
<label for="form-rating">Rating</label>
<input id="form-rating" type="number" name="rating" value="{{ .Wine.Rating }}" placeholder="Rating">
</div>
<div class="pure-control-group">
<label for="form-new-picture">New picture</label>
<input id="form-new-picture" type="file" name="picture" accept="image/png, image/jpeg">
<!-- TODO: add a button to remove the image -->
</div>
</fieldset>
<details>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment