當前位置: 首頁>>代碼示例>>Golang>>正文


Golang PutPolicy.Token方法代碼示例

本文整理匯總了Golang中github.com/qiniu/api/v6/rs.PutPolicy.Token方法的典型用法代碼示例。如果您正苦於以下問題:Golang PutPolicy.Token方法的具體用法?Golang PutPolicy.Token怎麽用?Golang PutPolicy.Token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/qiniu/api/v6/rs.PutPolicy的用法示例。


在下文中一共展示了PutPolicy.Token方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: qiniusave

func qiniusave(file string) (url string, err error) {

	var key string

	for _, key = range strings.Split(file, "/") {

	}

	conf.ACCESS_KEY = setting.AccessKeyID
	conf.SECRET_KEY = setting.AccessKeysecret

	url = "http://" + setting.Endpoint + "/" + key

	putPolicy := rs.PutPolicy{Scope: setting.Bucket}
	uptoken := putPolicy.Token(nil)

	var ret io.PutRet
	var extra = &io.PutExtra{}
	err = io.PutFile(nil, &ret, uptoken, key, file, extra)
	if err != nil {
		return "", err
	} else {
		return url, nil
	}

}
開發者ID:CodeJuan,項目名稱:dockyard,代碼行數:26,代碼來源:qiniu.go

示例2: upFile

func upFile(localFile, bucketName, key string) error {

	policy := rs.PutPolicy{
		Scope: bucketName + ":" + key,
	}
	return qio.PutFile(nil, nil, policy.Token(nil), key, localFile, nil)
}
開發者ID:jango2015,項目名稱:api.v6,代碼行數:7,代碼來源:rsf_api_test.go

示例3: TestPrivateImageView

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
	}
}
開發者ID:jango2015,項目名稱:api.v6,代碼行數:34,代碼來源:image_view_test.go

示例4: token

func (helper *QiniuHelper) token(bucketName string) string {
	if helper.cache != nil {
		tk, ok := helper.cache.Get(fmt.Sprintf("%s:%s", helper.AccessKey, bucketName))
		if ok {
			return tk.(string)
		}
	}

	duration := time.Hour
	putPolicy := rs.PutPolicy{
		Scope:   bucketName,
		Expires: 3600,
		// CallbackUrl:  callbackUrl,
		// CallbackBody: callbackBody,
		// ReturnUrl:    returnUrl,
		// ReturnBody:   returnBody,
		// AsyncOps:     asyncOps,
		// EndUser:      endUser,
		// Expires:      expires,
	}

	tk2 := putPolicy.Token(nil)
	if helper.cache != nil {
		helper.cache.Set(fmt.Sprintf("%s:%s", helper.AccessKey, bucketName), tk2, duration)
	}
	return tk2
}
開發者ID:h2object,項目名稱:h2object,代碼行數:27,代碼來源:qiniu.go

示例5: genUptoken

func genUptoken(bucket, key string) string {
	gr := cfg.Gorelease
	if gr.Token != "" {
		log.Println("Use gorelease, key:", key)
		u := url.URL{
			Scheme: "http",
			Host:   gr.Host,
			Path:   "/uptoken",
		}
		query := u.Query()
		query.Set("private_token", gr.Token)
		query.Set("bucket", bucket)
		query.Set("key", key)
		u.RawQuery = query.Encode()
		resp, err := http.Get(u.String())
		if err != nil {
			log.Fatal(err)
		}
		defer resp.Body.Close()
		if resp.StatusCode != http.StatusOK {
			sysio.Copy(os.Stdout, resp.Body)
			log.Fatalf("status: %d", resp.StatusCode)
		}
		uptoken, _ := ioutil.ReadAll(resp.Body)
		return string(uptoken)
	}
	putPolicy := rs.PutPolicy{
		Scope: bucket + ":" + key,
	}
	return putPolicy.Token(nil)
}
開發者ID:gorelease,項目名稱:qsync,代碼行數:31,代碼來源:main.go

示例6: genUptoken

func genUptoken(bucket string, key string) string {
	policy := rs.PutPolicy{
		Scope: bucket + ":" + key,
	}
	policy.Expires = uint32(time.Now().Unix()) + 1800
	policy.FsizeLimit = 20 << 20 // 20M
	return policy.Token(nil)
}
開發者ID:gorelease,項目名稱:qntoken,代碼行數:8,代碼來源:main.go

示例7: ResumablePut

func ResumablePut(cmd string, params ...string) {
	if len(params) == 3 || len(params) == 4 || len(params) == 5 {
		bucket := params[0]
		key := params[1]
		localFile := params[2]
		mimeType := ""
		upHost := "http://upload.qiniu.com"
		if len(params) == 4 {
			param := params[3]
			if strings.HasPrefix(param, "http") {
				upHost = param
			} else {
				mimeType = param
			}
		}
		if len(params) == 5 {
			mimeType = params[3]
			upHost = params[4]
		}
		accountS.Get()
		mac := digest.Mac{accountS.AccessKey, []byte(accountS.SecretKey)}
		policy := rs.PutPolicy{}
		policy.Scope = bucket
		putExtra := rio.PutExtra{}
		if mimeType != "" {
			putExtra.MimeType = mimeType
		}
		conf.UP_HOST = upHost
		progressHandler := ProgressHandler{
			BlockIndices:    make([]int, 0),
			BlockProgresses: make(map[int]float32),
		}
		putExtra.Notify = progressHandler.Notify
		putExtra.NotifyErr = progressHandler.NotifyErr
		uptoken := policy.Token(&mac)
		putRet := rio.PutRet{}
		startTime := time.Now()
		fStat, statErr := os.Stat(localFile)
		if statErr != nil {
			log.Error("Local file error", statErr)
			return
		}
		fsize := fStat.Size()
		err := rio.PutFile(nil, &putRet, uptoken, key, localFile, &putExtra)
		if err != nil {
			log.Error("Put file error", err)
		} else {
			fmt.Println("\r\nPut file", localFile, "=>", bucket, ":", putRet.Key, "(", putRet.Hash, ")", "success!")
		}
		lastNano := time.Now().UnixNano() - startTime.UnixNano()
		lastTime := fmt.Sprintf("%.2f", float32(lastNano)/1e9)
		avgSpeed := fmt.Sprintf("%.1f", float32(fsize)*1e6/float32(lastNano))
		fmt.Println("Last time:", lastTime, "s, Average Speed:", avgSpeed, "KB/s")
	} else {
		CmdHelp(cmd)
	}
}
開發者ID:jbasttdi,項目名稱:qshell,代碼行數:57,代碼來源:putfile.go

示例8: UploadReader

func UploadReader(reader io.Reader, name string) error {
	var err error
	var ret qio.PutRet
	ACCESS_KEY = "NPfcHtb0e2EH7lCmmJot21MRr0lCel81S-QlUaJF"
	SECRET_KEY = "6DzF_oVRYhBkq0mqb4txThza_IfQEUey107VXaPq"
	var policy = qrs.PutPolicy{
		Scope: "isaac",
	}
	err = qio.Put(nil, &ret, policy.Token(nil), name, reader, nil)
	return err
}
開發者ID:joveth,項目名稱:isaac_web,代碼行數:11,代碼來源:qiniutool.go

示例9: uptoken

func uptoken(bucketName string) string {
	putPolicy := qnrs.PutPolicy{
		Scope: bucketName,
		//CallbackUrl: callbackUrl,
		//CallbackBody:callbackBody,
		//ReturnUrl:   returnUrl,
		//ReturnBody:  returnBody,
		//AsyncOps:    asyncOps,
		//EndUser:     endUser,
		//Expires:     expires,
	}
	return putPolicy.Token(nil)
}
開發者ID:8legd,項目名稱:qor-media_library,代碼行數:13,代碼來源:qiniu.go

示例10: UploadFile

func UploadFile(localFile string, destName string) (addr string, err error) {
	policy := new(rs.PutPolicy)
	policy.Scope = QiniuScope
	uptoken := policy.Token(nil)

	var ret io.PutRet
	var extra = new(io.PutExtra)
	err = io.PutFile(nil, &ret, uptoken, destName, localFile, extra)
	if err != nil {
		return
	}
	addr = "http://" + QiniuScope + ".qiniudn.com/" + destName
	return
}
開發者ID:Chenguozhong,項目名稱:beego-blog,代碼行數:14,代碼來源:qiniu.go

示例11: InitQiniu

func InitQiniu() {
	conf.ACCESS_KEY = config.Config["qiniu_access_key"]
	conf.SECRET_KEY = config.Config["qiniu_secret_key"]

	putPolicy := rs.PutPolicy{
		Scope: config.Config["qiniu_bucket_name"],
		// CallbackUrl:  callbackUrl,
		// CallbackBody: callbackBody,
		// ReturnUrl:    returnUrl,
		// ReturnBody:   returnBody,
		// AsyncOps:     asyncOps,
		// EndUser:      endUser,
		// Expires:      expires,
	}

	uptoken = putPolicy.Token(nil)
}
開發者ID:NeoChow,項目名稱:studygolang,代碼行數:17,代碼來源:uploader.go

示例12: PutFile

func (driver *QiniuDriver) PutFile(key string, data io.Reader, appendData bool) (int64, error) {
	var err error
	var ret qio.PutRet
	var extra = &qio.PutExtra{}

	putPolicy := rs.PutPolicy{
		Scope: driver.bucket,
	}
	uptoken := putPolicy.Token(nil)

	rd := CountReader(data)
	err = qio.Put(nil, &ret, uptoken, strings.TrimLeft(key, "/"), rd, extra)
	if err != nil {
		return 0, err
	}

	return int64(rd.Size()), nil
}
開發者ID:goftp,項目名稱:qiniu-driver,代碼行數:18,代碼來源:driver.go

示例13: uploadAvatarToQiniu

// 上傳到七牛,並返回文件名
func uploadAvatarToQiniu(file io.ReadCloser, contentType string) (filename string, err error) {
	isValidateType := false
	for _, imgType := range []string{"image/png", "image/jpeg"} {
		if imgType == contentType {
			isValidateType = true
			break
		}
	}

	if !isValidateType {
		return "", errors.New("文件類型錯誤")
	}

	filenameExtension := ".jpg"
	if contentType == "image/png" {
		filenameExtension = ".png"
	}

	// 文件名:32位uuid,不帶減號和後綴組成
	filename = strings.Replace(uuid.NewUUID().String(), "-", "", -1) + filenameExtension

	key := "avatar/" + filename

	ret := new(qiniuIo.PutRet)

	var policy = rs.PutPolicy{
		Scope: "gopher",
	}

	err = qiniuIo.Put(
		nil,
		ret,
		policy.Token(nil),
		key,
		file,
		nil,
	)

	if err != nil {
		return "", err
	}

	return filename, nil
}
開發者ID:zhaoshiling1017,項目名稱:gopher,代碼行數:45,代碼來源:account.go

示例14: TestAll

func TestAll(t *testing.T) {

	policy := rs.PutPolicy{
		Scope: bucket,
	}
	token := policy.Token(nil)
	params := map[string]string{"x:1": "1"}
	extra := &PutExtra{
		ChunkSize: 128,
		MimeType:  "text/plain",
		Notify:    blockNotify,
		Params:    params,
	}

	testPut(t, token, nil)
	testPutWithoutKey(t, token, extra)
	testPutFile(t, token, extra)
	testPutFileWithoutKey(t, token, extra)
	testXVar(t, token, extra)
}
開發者ID:jango2015,項目名稱:api.v6,代碼行數:20,代碼來源:resumable_api_test.go

示例15: NewUptoken

//內存中new一個uptoken,沒有持久化的,有效期為從現在開始的第X天
func (this *Bucket) NewUptoken() error {
	if this.Name == "" || this.Ak == "" || this.Sk == "" {
		return errors.New("Bucket的Name/Ak/Sk為空,無法生成Uptoken")
	}
	if this.Life == 0 {
		this.Life = 380
	}
	this.Expires = time.Now().Add(time.Duration(this.Life) * DAY)
	putPolicy := rs.PutPolicy{
		Scope:   this.Name,
		Expires: uint32(this.Expires.Unix()),
		//CallbackUrl: callbackUrl,
		//CallbackBody:callbackBody,
		//ReturnUrl:   returnUrl,
		//ReturnBody:  returnBody,
		//AsyncOps:    asyncOps,
		//EndUser:     endUser,
	}
	this.Uptoken = putPolicy.Token(&digest.Mac{this.Ak, []byte(this.Sk)})
	this.HasError = false
	return nil
}
開發者ID:empirefox,項目名稱:iniu-old,代碼行數:23,代碼來源:bucket.go


注:本文中的github.com/qiniu/api/v6/rs.PutPolicy.Token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。