Fix:
//remove the io.writer argument requirement at top
func uploadFile(bucket, object string) error {
//...snip...
//remove the following at the bottom of the function
fmt.Fprintf(w, "Blob %v uploaded.\n", object)
//shoutout to Derek Perkins on the Go (Gophers) Slack
Opinion: There needs to be many more examples of the client usage for Go end-to-end
hi all- new to go in general. i'm trying to make sense of the storage client
sample script usage.I place the script into a sample file and then call the function 'uploadFile' from the main function as the driver via:
bucket := "mybucketname"
object := "myobjectname"
upploadFile(bucket, object)
The error is that I'm missing whatever w io.writer means:
not enough arguments in call to uploadFile
have (string, string)
want (io.Writer, string, string)
I have no idea what it wants from me regarding that. Multiple blogs/tutorials state what it does and one even said it was implicit so it doesn't need a declaration. The write object in the sample code looks like it's being created and then executed at the bottom of the function. If I try to remove the argument requirement in the function; I still get an error. Yet at the bottom it creates a new writer?
// Upload an object with storage.Writer.
wc := o.NewWriter(ctx)
if _, err = io.Copy(wc, f); err != nil {
return fmt.Errorf("io.Copy: %v", err)
}
if err := wc.Close(); err != nil {
return fmt.Errorf("Writer.Close: %v", err)
}
fmt.Fprintf(w, "Blob %v uploaded.\n", object)
return nil
Can someone show me how to actually use this or perform a very basic service account authenticated (I have the JSON file already) action to upload X local file to Y target bucket path?