简体   繁体   中英

File Upload Failed using SIRIS

I want to upload a file to the server using SIRIS and Postman.

Go Program

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

在此处输入图片说明

But Postman only can get the error message:

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

Why does this happen?

To correctly hanle file upload html form should have attribute

enctype="multipart/form-data"

在此处输入图片说明

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

PS I do not recommend to use Iris.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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