0

我想使用 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 只能得到错误信息:

上传
时出错:请求 Content-Type 不是 multipart/form-data

为什么会这样?

4

1 回答 1

2

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

enctype="multipart/form-data"

在此处输入图像描述

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

PS 我不推荐使用 Iris。

于 2017-10-04T03:19:37.183 回答