1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

file-server example: add upload using javascript button

Former-commit-id: caaec95388e691c2db27a55e649c758f93ab537c
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-05 15:12:19 +03:00
parent 57dc64625d
commit bdfe8de66d
2 changed files with 34 additions and 7 deletions

View File

@@ -20,6 +20,8 @@ func init() {
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
// Serve assets (e.g. javascript, css).
// app.HandleDir("/public", "./public")
app.Get("/", index)
@@ -47,10 +49,14 @@ func uploadView(ctx iris.Context) {
ctx.View("upload.html", token)
}
const maxSize = 10 * iris.MB
func upload(ctx iris.Context) {
ctx.SetMaxRequestBodySize(maxSize)
_, err := ctx.UploadFormFiles("./uploads", beforeSave)
if err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
ctx.StopWithError(iris.StatusPayloadTooRage, err)
return
}