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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度