adamll
adamll

Reputation: 11

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.

Upvotes: 0

Views: 309

Answers (1)

adamll
adamll

Reputation: 11

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

Upvotes: 1

Related Questions