بارگذاری فایل تکی

const maxSize = 8 * iris.MB

func main() {
    app := iris.Default()

    app.Post("/upload", func(ctx iris.Context) {
        // تنظیم محدودیت اندازه بدنه درخواست، که حداکثر اندازه بارگذاری فایل را محدود می کند (پیش فرض 32 مگابایت)
        ctx.SetMaxRequestBodySize(maxSize)
        // یا
        // app.Use(iris.LimitRequestBodySize(maxSize))
        // یا
        // iris.WithPostMaxMemory(maxSize)

        // خواندن فایل
        file, fileHeader, err:= ctx.FormFile("file")
        if err != nil {
            ctx.StopWithError(iris.StatusBadRequest, err)
            return
        }

        // ذخیره فایل بارگذاری شده در دایرکتوری مشخص شده
        dest := filepath.Join("./uploads", fileHeader.Filename)
        ctx.SaveFormFile(fileHeader, dest)

        ctx.Writef("فایل: %s بارگذاری شد!", fileHeader.Filename)
    })

    app.Listen(":8080")
}

تست بارگذاری یک فایل

curl -X POST http://localhost:8080/upload \
  -F "file=@/Users/kataras/test.zip" \
  -H "Content-Type: multipart/form-data"

بارگذاری چند فایل

func main() {
    app := iris.Default()
    app.Post("/upload", func(ctx iris.Context) {
        // خواندن چند فایل
        files, n, err := ctx.UploadFormFiles("./uploads")
        if err != nil {
            ctx.StopWithStatus(iris.StatusInternalServerError)
            return
        }

        ctx.Writef("%d فایل از جمع اندازه %d بارگذاری شد!", len(files), n)
    })

    app.Listen(":8080", iris.WithPostMaxMemory(8 * iris.MB))
}

تست بارگذاری چند فایل

curl -X POST http://localhost:8080/upload \
  -F "upload[]=@/Users/kataras/test1.zip" \
  -F "upload[]=@/Users/kataras/test2.zip" \
  -H "Content-Type: multipart/form-data"