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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…