【问题标题】:Can not upload any file to google cloud storage无法将任何文件上传到谷歌云存储
【发布时间】:2021-01-24 17:48:50
【问题描述】:

我正在尝试从本地构建的 go 应用程序将文件上传到云存储。问题是我总是收到这个错误:```panic: runtime error: invalid memory address or nil pointer dereference [信号SIGSEGV:分段违规代码=0x1 addr=0x28 pc=0x18e71e1]

cloud.google.com/go/storage.(*Writer).open.func1(0xc000146480, 0xc00000c1e0, 0xc000206010, 0xc000512070, 0x1, 0x1)
        /Users/adamlukacka/go/pkg/mod/cloud.google.com/go/storage@v1.12.0/writer.go:128 +0xe1
created by cloud.google.com/go/storage.(*Writer).open
        /Users/adamlukacka/go/pkg/mod/cloud.google.com/go/storage@v1.12.0/writer.go:118 +0x412
exit status 2

这是我的代码:

        bucket := "my-unique-bucket-name"
        object := i.Name
        ctx := context.Background()
        fmt.Println("ctx", ctx)
        client, err := storage.NewClient(ctx)

        if client == nil {
            fmt.Println("client is nil")
        }

当我尝试获取新客户端时,它返回 nil。

这个实现在生产环境中运行良好,但我无法弄清楚我在本地做错了什么。

我可以从终端上传图像,并且我的项目设置为默认值。所有设置似乎都可以,但它不起作用。我试图在另一台 Mac 上克隆我的项目,但我看到了同样的问题。

【问题讨论】:

    标签: file upload cloud storage


    【解决方案1】:

    在解决这个问题 2 天后发现了这个问题。这个命令解决了它gcloud auth application-default login

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      相关资源
      最近更新 更多