From bdfe8de66d5b2ae86eb393cefa1eb8d25d2e34bd Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Sun, 5 Jul 2020 15:12:19 +0300 Subject: [PATCH] file-server example: add upload using javascript button Former-commit-id: caaec95388e691c2db27a55e649c758f93ab537c --- _examples/file-server/file-server/main.go | 8 ++++- .../file-server/file-server/views/upload.html | 33 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/_examples/file-server/file-server/main.go b/_examples/file-server/file-server/main.go index 0ce54002..3e0bdb68 100644 --- a/_examples/file-server/file-server/main.go +++ b/_examples/file-server/file-server/main.go @@ -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 } diff --git a/_examples/file-server/file-server/views/upload.html b/_examples/file-server/file-server/views/upload.html index 6954b82f..a278be2e 100644 --- a/_examples/file-server/file-server/views/upload.html +++ b/_examples/file-server/file-server/views/upload.html @@ -1,17 +1,38 @@ + Upload Files + -
- - - + + + + +
+ + + \ No newline at end of file