示例#1
0
func TestNewSign(t *testing.T) {
	s, err := sign.New("AAAAAAAA", time.Unix(0, 0), "BBBBBBBB", "CCCCCCCC", "DDDDDDDD", 100, 100)
	if err != nil {
		t.Error(err)
	}

	if s.Policy != "eyJleHBpcmF0aW9uIjoiMTk3MC0wMS0wMVQwMDowMDowMFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJCQkJCQkJCQiJ9LHsia2V5IjoiQ0NDQ0NDQ0MifSx7IkNvbnRlbnQtVHlwZSI6IkREREREREREIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMTAwLDEwMF1dfQ==" {
		t.Error("wrong policy")
	}
	if s.Signature != "jDz2g/k6nCo8iKgAd1r27sp4y+8=" {
		t.Error("wrong signature")
	}
}
示例#2
0
func (p Publisher) Publish(accessKeyID, secretAccessKey, bucket string, duration time.Duration) (f Form, err error) {
	expiration := time.Now().Add(duration)
	key := uuid.NewV4().String()

	s, err := sign.New(secretAccessKey, expiration, bucket, key, p.ContentType, p.Size, p.Size)
	if err != nil {
		return
	}

	f.URL = fmt.Sprintf("https://%s.s3.amazonaws.com/", bucket)
	f.Fields = map[string]string{
		"AWSAccessKeyId": accessKeyID,
		"policy":         s.Policy,
		"signature":      s.Signature,
		"Content-Type":   p.ContentType,
		"key":            key,
	}

	return
}