func TestPrivateImageView(t *testing.T) { //首先上传一个图片 用于测试 policy := rs.PutPolicy{ Scope: bucket + ":" + key, } err := io.PutFile(nil, nil, policy.Token(nil), key, localFile, nil) if err != nil { t.Errorf("TestPrivateImageView failed: %v", err) return } rawUrl := makeUrl(key) iv := ImageView{ Mode: 2, Height: 250, Quality: 80, } imageViewUrl := iv.MakeRequest(rawUrl) p := rs.GetPolicy{} imageViewUrlWithToken := p.MakeRequest(imageViewUrl, nil) resp, err := http.DefaultClient.Get(imageViewUrlWithToken) if err != nil { t.Errorf("TestPrivateImageView failed: %v", err) return } defer resp.Body.Close() if (resp.StatusCode / 100) != 2 { t.Errorf("TestPrivateImageView failed: resp.StatusCode = %v", resp.StatusCode) return } }
// @gist downloadUrl func downloadUrl(domain, key string) string { baseUrl := rs.MakeBaseUrl(domain, key) policy := rs.GetPolicy{} return policy.MakeRequest(baseUrl, nil) }