Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

Can not upload any file to google cloud storage

I am trying to upload files to cloud storage from my local build of go app. Issue is that I am always getting this error: ```panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=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/[email protected]/writer.go:128 +0xe1
created by cloud.google.com/go/storage.(*Writer).open
        /Users/adamlukacka/go/pkg/mod/cloud.google.com/go/[email protected]/writer.go:118 +0x412
exit status 2

This is my code:

        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")
        }

When I try to get new client it returns nil.

This implementation works fine on production but I can not work it out what am I doing wrong locally.

I can upload images from terminal and I have my project set to default. All settings seems OK but it does not work. I tried to clone my project on another Mac and I saw same issue.

question from:https://stackoverflow.com/questions/65874001/can-not-upload-any-file-to-google-cloud-storage

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found the issue after 2 days of fighting this. This command resolved it gcloud auth application-default login


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...