kataras / kataras/iris

[BUG]Official single file upload problem

Open
#1,759 0 comments 0 reactions 1 assignee Claimed by @kataras View on GitHub
🐞 type:bug
Dominant language
Go
Stars
25.6k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
Official single file upload problem

**To Reproduce**
Steps to reproduce the behavior:

SaveFormFile source code
```
// SaveFormFile saves a result of `FormFile` to the "dest" disk full path (directory + filename).
// See `FormFile` and `UploadFormFiles` too.
func (ctx *Context) SaveFormFile(fh *multipart.FileHeader, dest string) (int64, error) {
src, err := fh.Open()
if err != nil {
return 0, err
}
defer src.Close()

out, err := os.Create(dest)
if err != nil {
return 0, err
}
defer out.Close()

return io.Copy(out, src)
}
```

The official example
```
// single file
file, fileHeader, err:= ctx.FormFile("file")
if err != nil {
ctx.StopWithError(iris.StatusBadRequest, err)
return
}

// Upload the file to specific destination.
dest := filepath.Join("./uploads", fileHeader.Filename)
ctx.SaveFormFile(file, dest)
```

The first argument is passed in multipart.fileHeader, but the example uses File

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: mac

**iris.Version**
- go 1.16
- github.com/kataras/iris/v12 v12.2.0-alpha2.0.20210422110000-6219e5713558

Please make sure the bug is reproducible over the `master` branch:

```sh
$ cd PROJECT
$ go get -u github.com/kataras/iris/v12@master
$ go run .
```

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.