首页 > 解决方案 > 无法将任何文件上传到谷歌云存储

问题描述

我正在尝试从本地构建的 go 应用程序将文件上传到云存储。问题是我总是收到这个错误:```恐慌:运行时错误:无效的内存地址或零指针取消引用[信号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 上克隆我的项目,但我看到了同样的问题。

标签: fileuploadcloudstorage

解决方案


经过2天的斗争后发现了这个问题。该命令解决了它gcloud auth application-default login


推荐阅读