UploadFile uploads a file to Google Storage
(src, dst, bucketName string, public bool)
| 108 | |
| 109 | // UploadFile uploads a file to Google Storage |
| 110 | func (g GCPClient) UploadFile(src, dst, bucketName string, public bool) error { |
| 111 | log.Infof("Uploading file %s to Google Storage as %s", src, dst) |
| 112 | f, err := os.Open(src) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | defer func() { _ = f.Close() }() |
| 117 | |
| 118 | objectCall := g.storage.Objects.Insert(bucketName, &storage.Object{Name: dst}).Media(f) |
| 119 | |
| 120 | if public { |
| 121 | objectCall.PredefinedAcl("publicRead") |
| 122 | } |
| 123 | |
| 124 | _, err = objectCall.Do() |
| 125 | if err != nil { |
| 126 | return err |
| 127 | } |
| 128 | log.Infof("Upload Complete!") |
| 129 | fmt.Println("gs://" + bucketName + "/" + dst) |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // CreateImage creates a GCP image using the source from Google Storage |
| 134 | func (g GCPClient) CreateImage(name, storageURL, family string, nested, uefi, replace bool) error { |
no test coverage detected