简体   繁体   中英

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/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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM