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

minor improvements

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-31 09:40:27 +03:00
parent 5700690dea
commit 8d99b46801
6 changed files with 66 additions and 49 deletions

View File

@@ -102,7 +102,7 @@ func uploadView(ctx iris.Context) {
func upload(ctx iris.Context) {
ctx.SetMaxRequestBodySize(maxSize)
_, err := ctx.UploadFormFiles(uploadDir, beforeSave)
_, _, err := ctx.UploadFormFiles(uploadDir, beforeSave)
if err != nil {
ctx.StopWithError(iris.StatusPayloadTooRage, err)
return
@@ -111,12 +111,13 @@ func upload(ctx iris.Context) {
ctx.Redirect("/files")
}
func beforeSave(ctx iris.Context, file *multipart.FileHeader) {
func beforeSave(ctx iris.Context, file *multipart.FileHeader) bool {
ip := ctx.RemoteAddr()
ip = strings.ReplaceAll(ip, ".", "_")
ip = strings.ReplaceAll(ip, ":", "_")
file.Filename = ip + "-" + file.Filename
return true
}
func deleteFile(ctx iris.Context) {