Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

cloud - googleapi: Error 404: The requested project was not found., notFound

I am trying to upload image from my local go backend to google cloud but I am getting this error googleapi: Error 404: The requested project was not found., notFound

When I first set up my project I used app engine and then switched it to cloud run. All if working fine when I deploy my project live but not when trying to upload file from local machine.

When I try to upload it through terminal with this command gsutil cp OBJECT_LOCATION gs://DESTINATION_BUCKET_NAME/ then it also works fine.

Any ideas what am I doing wrong and if switching from app engine to cloud run could cause this issue?

        object := i.Name
        ctx := context.Background()
        client, err := storage.NewClient(ctx)
        if err != nil {
            fmt.Errorf("storage.NewClient: %v", err)
        }
        defer client.Close()

        // Form image file which will be uploaded
        f, _, err := r.FormFile("image")
        if err != nil {
            fmt.Errorf("os.Open: %v", err)
        }
        defer f.Close()

        ctx, cancel := context.WithTimeout(ctx, time.Second*50)
        defer cancel()

        // Upload an object with storage.Writer.
        wc := client.Bucket(bucket).Object(object).NewWriter(ctx)
        if _, err = io.Copy(wc, f); err != nil {
            fmt.Errorf("io.Copy: %v", err)
        }
        if err := wc.Close(); err != nil {
            fmt.Println("Error Is happening here", err)
            fmt.Errorf("Writer.Close: %v", err)
        }```
question from:https://stackoverflow.com/questions/65868856/googleapi-error-404-the-requested-project-was-not-found-notfound

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...