使用 SIRIS 上传文件失败

File Upload Failed using SIRIS

我想使用 SIRIS 和 Postman 上传文件到服务器。

去编程

package main

import (
    "github.com/go-siris/siris"
)

func main() {
    app := siris.New()
    app.Post("/", handleFileUpload)
    app.Run(siris.Addr(":8080"))
}

func handleFileUpload(ctx siris.Context) {
    ctx.Writef("Hello<br/>")
    file, info, err := ctx.FormFile("filee")
    if err != nil {
        ctx.StatusCode(iris.StatusInternalServerError)
        ctx.HTML("Error while uploading: <b>" + err.Error() + "</b>")
        return
    }
    defer file.Close()
    fn := info.Filename
    ctx.Writef("File Name: " + fn)
}

邮递员

但是Postman只能得到错误信息:

Hello
Error while uploading: request Content-Type isn't multipart/form-data

为什么会这样?

要正确处理文件上传 html 表单应该有属性

enctype="multipart/form-data"

https://www.w3schools.com/php/php_file_upload.asp

P.S。我不推荐使用 Iris。