示例#1
0
func (pc *PicCloud) DownloadWithSign(userid string, fileid string, filename string) error {
	reqUrl := pc.getDownloadUrl(userid, fileid)
	sign, err := sign.AppSignOnceV2(pc.Appid, pc.SecretId, pc.SecretKey, pc.Bucket, userid, fileid)
	if nil != err {
		return err
	}

	return pc.DownloadByUrl(reqUrl+"?sign="+sign, filename)
}
示例#2
0
func (pc *PicCloud) Copy(userid string, fileid string) (info UrlInfo, err error) {
	reqUrl := pc.getUrl(userid, fileid) + "/copy"
	sign, err := sign.AppSignOnceV2(pc.Appid, pc.SecretId, pc.SecretKey, pc.Bucket, userid, fileid)
	if nil != err {
		return
	}

	req, err := http.NewRequest("POST", reqUrl, nil)
	if nil != err {
		return
	}
	req.Header.Set("HOST", "web.image.myqcloud.com")
	req.Header.Set("user-agent", "qcloud-go-sdk")
	req.Header.Set("Authorization", "QCloud "+sign)

	var client http.Client
	resp, err := client.Do(req)
	if nil != err {
		fmt.Printf("http error, err=%s", err.Error())
		return
	}
	defer resp.Body.Close()

	data, err := ioutil.ReadAll(resp.Body)
	if nil != err {
		return
	}

	code, message, js, err := pc.parseRsp(data)
	if nil != err {
		return
	}
	if code != 0 {
		desc := fmt.Sprintf("rsp error, code=%d, message=%s", code, message)
		err = errors.New(desc)
		return
	}

	info.Url, _ = js.Get("data").Get("url").String()
	info.DownloadUrl, _ = js.Get("data").Get("download_url").String()
	info.Fileid = info.Url[strings.LastIndex(info.Url, "/")+1:]
	return
}
示例#3
0
func (pc *PicCloud) Delete(userid string, fileid string) error {
	reqUrl := pc.getUrl(userid, fileid) + "/del"
	sign, err := sign.AppSignOnceV2(pc.Appid, pc.SecretId, pc.SecretKey, pc.Bucket, userid, fileid)
	if nil != err {
		return err
	}

	req, err := http.NewRequest("POST", reqUrl, nil)
	if nil != err {
		return err
	}
	req.Header.Set("HOST", "web.image.myqcloud.com")
	req.Header.Set("user-agent", "qcloud-go-sdk")
	req.Header.Set("Authorization", "QCloud "+sign)

	var client http.Client
	resp, err := client.Do(req)
	if nil != err {
		fmt.Printf("http error, err=%s", err.Error())
		return err
	}
	defer resp.Body.Close()

	data, err := ioutil.ReadAll(resp.Body)
	if nil != err {
		return err
	}

	code, message, _, err := pc.parseRsp(data)
	if nil != err {
		return err
	}
	if code != 0 {
		desc := fmt.Sprintf("rsp error, code=%d, message=%s", code, message)
		return errors.New(desc)
	}

	return nil
}
示例#4
0
func (pc *PicCloud) SignOnce(userid string, fileid string) (string, error) {
	return sign.AppSignOnceV2(pc.Appid, pc.SecretId, pc.SecretKey, pc.Bucket, userid, fileid)
}