繁体   English   中英

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

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

为什么会这样?

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

enctype="multipart/form-data"

在此处输入图片说明

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

PS我不建议使用虹膜。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM