I have a fairly simple code for uploading files to Google Cloud Storage using Golang.
func upload(object *storage.ObjectHandle, b []byte) error {
w := object.NewWriter(context.Background())
if _, err = w.Write(b); err != nil {
return err
}
return w.Close()
}
I have uploaded multitudes of files without any problems, but yesterday I noticed that one of the files was damaged. I'm fairly certain that the file was damaged during the upload as I name the files based on MD5 hash of its contents. I believe the Google Cloud Storage should've returned an error when calling the w.Close()
but it didn't. What's the best way to make sure that the upload always fails when the transfer is interrupted/damaged?