Example #1
0
func (helper *QiniuHelper) Put(bucket string, key string, rd sysio.Reader, size int64) (string, error) {
	token := helper.token(bucket)

	var ret io.PutRet
	var extra = &io.PutExtra{
	// Params:   params,
	// MimeType: contentType,
	// Crc32:    crc32,
	// CheckCrc: CheckCrc,
	}
	if err := io.Put2(nil, &ret, token, key, rd, size, extra); err != nil {
		if helper.cache != nil {
			helper.cache.Delete(fmt.Sprintf("%s:%s", helper.AccessKey, bucket))
		}
		return "", err
	}
	return ret.Key, nil
}
Example #2
0
func main() {
	ACCESS_KEY = "xxxxxxxx"
	SECRET_KEY = "xxxxxxxx"

	var ret qnio.PutRet

	var extra = &qnio.PutExtra{
		MimeType: "image/jepg",
		CheckCrc: 0,
	}
	key := "1024x1024.jpg"

	scope := fmt.Sprintf("skypixeltest:%s", key)

	putPolicy := rs.PutPolicy{
		Scope: scope,
		// Expires:      expires,
	}
	uptoken := putPolicy.Token(nil)

	fi, err := os.Open("/Users/qpzhang/Downloads/1024x1024.jpg")
	st, _ := fi.Stat()
	if err != nil {
		panic(err)
	}
	defer fi.Close()
	data := bufio.NewReader(fi)

	fmt.Println("size ", st.Size())
	err = qnio.Put2(nil, &ret, uptoken, key, data, st.Size(), extra)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("put sucess......", ret)
	}
}