Exemple #1
0
func s3put(bb *bytes.Buffer, url string) error {
	r, _ := http.NewRequest("PUT", url, bb)
	r.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
	r.Header.Set("Content-Disposition", "attachment")
	r.Header.Set("X-Amz-Acl", "public-read")
	r.Header.Set("Content-Md5", b64md5(bb.Bytes()))
	s3.Sign(r, s3keys)
	resp, err := http.DefaultClient.Do(r)
	if err != nil {
		return err
	}
	if resp.StatusCode != 200 {
		body, _ := ioutil.ReadAll(resp.Body)
		return fmt.Errorf("s3 status %v putting %q: %q", resp.Status, url, string(body))
	}
	return nil
}
Exemple #2
0
func ExampleSign() {
	keys := s3.Keys{
		AccessKey: os.Getenv("S3_ACCESS_KEY"),
		SecretKey: os.Getenv("S3_SECRET_KEY"),
	}
	data := strings.NewReader("hello, world")
	r, _ := http.NewRequest("PUT", "https://example.s3.amazonaws.com/foo", data)
	r.ContentLength = int64(data.Len())
	r.Header.Set("Date", time.Now().UTC().Format(http.TimeFormat))
	r.Header.Set("X-Amz-Acl", "public-read")
	s3.Sign(r, keys)
	resp, err := http.DefaultClient.Do(r)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(resp.StatusCode)
}