Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

update upload.go to use Google Cloud Storage #1

Open
bradfitz opened this issue Sep 4, 2014 · 0 comments
Open

update upload.go to use Google Cloud Storage #1

bradfitz opened this issue Sep 4, 2014 · 0 comments

Comments

@bradfitz
Copy link
Contributor

bradfitz commented Sep 4, 2014

upload.go uses the Google Code file hosting, which no longer exists.

we now host winstrap.exe at https://storage.googleapis.com/winstrap/winstrap-20140711.exe

but that was done by hand. update upload.go to use GCS uploads instead. See for an example of how to do this at:

https://code.google.com/p/go/source/browse/dashboard/coordinator/buildongce/create.go?repo=tools

func writeCloudStorageObject(httpClient *http.Client) {
        content := os.Stdin
        const maxSlurp = 1 << 20
        var buf bytes.Buffer
        n, err := io.CopyN(&buf, content, maxSlurp)
        if err != nil && err != io.EOF {
                log.Fatalf("Error reading from stdin: %v, %v", n, err)
        }
        contentType := http.DetectContentType(buf.Bytes())

        req, err := http.NewRequest("PUT", "https://storage.googleapis.com/"+*writeObject, io.MultiReader(&buf, content))
        if err != nil {
                log.Fatal(err)
        }
        req.Header.Set("x-goog-api-version", "2")
        req.Header.Set("x-goog-acl", "public-read")
        req.Header.Set("Content-Type", contentType)
        res, err := httpClient.Do(req)
        if err != nil {
                log.Fatal(err)
        }
        if res.StatusCode != 200 {
                res.Write(os.Stderr)
                log.Fatalf("Failed.")
        }
        log.Printf("Success.")
        os.Exit(0)
}

It just needs an oauth2 http.Client & token first.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant