Screenshot uploads are saving

This commit is contained in:
Brian Buller 2017-06-21 15:07:17 -05:00
parent b9c95826d9
commit b283aacc6a
2 changed files with 30 additions and 29 deletions

View File

@ -1,12 +1,10 @@
package main package main
import ( import (
"fmt" "io/ioutil"
"io"
"mime/multipart"
"net/http" "net/http"
"os"
"strconv" "encoding/base64"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -46,31 +44,11 @@ func handleAdminGames(w http.ResponseWriter, req *http.Request, page *pageData)
} }
func saveScreenshots(teamId string, req *http.Request) error { func saveScreenshots(teamId string, req *http.Request) error {
err := req.ParseMultipartForm((1 << 10) * 24) file, _, err := req.FormFile("newssfile")
if err != nil { if err != nil {
return err return err
} }
data, err := ioutil.ReadAll(file)
for _, fheaders := range req.MultipartForm.File { str := base64.StdEncoding.EncodeToString(data)
for _, hdr := range fheaders { return dbSaveTeamGameScreenshot(teamId, &Screenshot{Image: str})
// open uploaded
var infile multipart.File
if infile, err = hdr.Open(); err != nil {
return err
}
// open destination
var outfile *os.File
if outfile, err = os.Create("./uploaded/" + hdr.Filename); err != nil {
return err
}
// 32K buffer copy
var written int64
if written, err = io.Copy(outfile, infile); err != nil {
return err
}
fmt.Println("uploaded file:" + hdr.Filename + ";length:" + strconv.Itoa(int(written)))
}
}
return nil
} }

View File

@ -0,0 +1,23 @@
<table id="games-table" class="hidden sortable pure-table pure-table-bordered center">
<thead>
<tr>
<th>Game Name</th>
</tr>
</thead>
<tbody>
{{ range $i, $v := .TemplateData.Games }}
<tr>
<td>{{ $v.Name }}</td>
</tr>
{{ end }}
</tbody>
</table>
<script>
snack.ready(function() {
var tableBody = document.querySelector("#games-table>tbody");
if(tableBody.children.length>0) {
// Show the table
document.getElementById('games-table').classList.remove('hidden');
}
});
</script>