drn5375 2017-07-21 01:45
浏览 1233
已采纳

* gin.Context类型没有字段或方法SaveUploadedFile

My code works fine on my Computer but I get this compile time error on my server after I moved the code to the debian server:

type *gin.Context has no field or method SaveUploadedFile

I use sample gin code to save file:

    if err := c.SaveUploadedFile(file, file.Filename); err != nil {
        c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
        return
    }

I have upgraded go to 1.8.3 on the server (to be of the same version as go on my desktop) and updated gin afterwards, hoping to solve the issue. But it did not.

Here is my go env:

root@s1:~# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/srv/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

I have also tried:

rm -rf $GOPATH/pkg/*

I also tried go build -a but get the same error.

So I'm left clueless and appreciate your hints to solve this issue.

  • 写回答

1条回答 默认 最新

  • drl9940 2017-07-21 02:00
    关注

    It seems your server is using old codebase of gin. Just checked the gin commit history.

    The method SaveUploadedFile added 5 days ago. So execute below command to pull the latest codebase on your server.

    go get -u github.com/gin-gonic/gin
    

    Then compile it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?