Example #1
0
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
	}
}
Example #2
0
func (driver *QiniuDriver) GetFile(key string, offset int64) (int64, io.ReadCloser, error) {
	stat, err := driver.Stat(key)
	if err != nil {
		return 0, nil, err
	}

	key = strings.TrimLeft(key, "/")

	domain := fmt.Sprintf("%s.qiniudn.com", driver.bucket)
	baseUrl := rs.MakeBaseUrl(domain, key)
	policy := rs.GetPolicy{}
	downUrl := policy.MakeRequest(baseUrl, nil)

	resp, err := http.Get(downUrl)
	if err != nil {
		return 0, nil, err
	}

	return stat.Size(), NewSkipReadCloser(resp.Body, offset), nil
}
Example #3
0
// @gist downloadUrl
func downloadUrl(domain, key string) string {
	baseUrl := rs.MakeBaseUrl(domain, key)
	policy := rs.GetPolicy{}
	return policy.MakeRequest(baseUrl, nil)
}