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

* 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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!