[英]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.