file - 无法将任何文件上传到谷歌云存储
问题描述
我正在尝试从本地构建的 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 上克隆我的项目,但我看到了同样的问题。
解决方案
经过2天的斗争后发现了这个问题。该命令解决了它gcloud auth application-default login
推荐阅读
- excel - 试图将写在一个范围内的每个字符串缩短为只有 4 个字符长
- html - 如何使用 Clearfix 解决浮动问题
- mysql - 按值大于 0 的列分组
- ios - 如何使用 CoreBluetooth 在后台 BLE 中读取特征
- node.js - 如何解析 azure 活动目录令牌,以及如何根据 node.js 中的 azure 令牌获取所有用户详细信息?
- docker - 如何在 Docker v.18.09.3 中停止 docker 之前使用 SystemD 运行 docker 命令
- java - 如何找到可以执行的最大参与者人数?
- dart - 如何在 Flutter with Colors 上设置强制 DropDownButton?
- java - 使用 PDFBox 更快的 PDF 页面尺寸?
- c# - 找不到类型或命名空间名称“OleDbConnection”(您是否缺少 using 指令或程序集引用?)