本文整理汇总了Golang中github.com/qiniu/api/rs.PutPolicy类的典型用法代码示例。如果您正苦于以下问题:Golang PutPolicy类的具体用法?Golang PutPolicy怎么用?Golang PutPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PutPolicy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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:kuguobing,项目名称:api,代码行数:7,代码来源:rsf_api_test.go
示例2: 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:HYQMartin,项目名称:star,代码行数:34,代码来源:image_view_test.go
示例3: UploadFile
func UploadFile(dir string, read io.Reader) (string, error) {
ACCESS_KEY = Webconfig.UploadConfig.QiniuAccessKey
SECRET_KEY = Webconfig.UploadConfig.QiniuSecretKey
extra := &qiniu_io.PutExtra{
// Bucket: "messagedream",
MimeType: "",
}
var policy = rs.PutPolicy{
Scope: "messagedream",
}
filename := strings.Replace(UUID(), "-", "", -1) + ".jpg"
body, _ := ioutil.ReadAll(read)
h := md5.New()
h.Write(body)
key := "static/upload/" + dir + "/" + filename
ret := new(qiniu_io.PutRet)
buf := bytes.NewBuffer(body)
return key, qiniu_io.Put(nil, ret, policy.Token(nil), key, buf, extra)
}
开发者ID:EPICPaaS,项目名称:MessageBlog,代码行数:26,代码来源:upload.go
示例4: handleUpload
func handleUpload(w http.ResponseWriter, req *http.Request) {
policy := rs.PutPolicy{Scope: BUCKET, ReturnUrl: "http://localhost:8765/uploaded", EndUser: "userId"}
token := policy.Token(nil)
log.Println("token:", token)
uploadForm := fmt.Sprintf(uploadFormFmt, token)
w.Write([]byte(uploadForm))
}
开发者ID:avivaxrq,项目名称:form-upload,代码行数:8,代码来源:main.go
示例5: handleUploadWithKeyAndCustomField
func handleUploadWithKeyAndCustomField(w http.ResponseWriter, req *http.Request) {
policy := rs.PutPolicy{Scope: BUCKET, ReturnUrl: "http://localhost:8765/uploaded"}
token := policy.Token()
log.Println("token:", token)
uploadForm := fmt.Sprintf(uploadWithkeyAndCustomFieldFmt, token)
w.Write([]byte(uploadForm))
}
开发者ID:yunan,项目名称:Go-Example,代码行数:8,代码来源:main.go
示例6: uploadImageHandler
// URL: /upload/image
// 编辑器上传图片,接收后上传到七牛
func uploadImageHandler(handler *Handler) {
file, header, err := handler.Request.FormFile("editormd-image-file")
if err != nil {
panic(err)
return
}
defer file.Close()
// 检查是否是jpg或png文件
uploadFileType := header.Header["Content-Type"][0]
filenameExtension := ""
if uploadFileType == "image/jpeg" {
filenameExtension = ".jpg"
} else if uploadFileType == "image/png" {
filenameExtension = ".png"
} else if uploadFileType == "image/gif" {
filenameExtension = ".gif"
}
if filenameExtension == "" {
handler.ResponseWriter.Header().Set("Content-Type", "text/html")
handler.ResponseWriter.Write(editorMdUploadImageResult(0, "", "不支持的文件格式,请上传 jpg/png/gif 图片"))
return
}
// 上传到七牛
// 文件名:32位uuid+后缀组成
filename := strings.Replace(uuid.NewUUID().String(), "-", "", -1) + filenameExtension
key := "upload/image/" + 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 {
panic(err)
handler.ResponseWriter.Header().Set("Content-Type", "text/html")
handler.ResponseWriter.Write(editorMdUploadImageResult(0, "", "图片上传到七牛失败"))
return
}
handler.ResponseWriter.Header().Set("Content-Type", "text/html")
handler.ResponseWriter.Write(editorMdUploadImageResult(1, "http://7xj1eq.com1.z0.glb.clouddn.com/"+key, ""))
}
开发者ID:makohill,项目名称:androidfancier.cn,代码行数:60,代码来源:views.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:joozo-gexia,项目名称:qshell,代码行数:57,代码来源:putfile.go
示例8: QiniuTokens
func (this *AdminController) QiniuTokens() {
bucket := models.Appconf.String("qiniu::bucket")
putPolicy := rs.PutPolicy{
Scope: bucket,
}
this.Data["json"] = putPolicy.Token(nil)
this.ServeJson()
}
开发者ID:jango2015,项目名称:Blog-3,代码行数:9,代码来源:admin.go
示例9: qntoken
// generate qiniu token
func qntoken(key string) string {
scope := defaultBulket + ":" + key
log.Infof("qiniu scrope: %s", scope)
policy := rs.PutPolicy{
Expires: uint32(time.Now().Unix() + 3600),
Scope: scope,
}
return policy.Token(nil)
}
开发者ID:kissthink,项目名称:gobuild2,代码行数:10,代码来源:xrpc.go
示例10: upFile
func upFile(bucket string, key string, localPath string) error {
var ret qiniuio.PutRet
policy := rs.PutPolicy{
Scope: bucket + ":" + key,
}
err := qiniuio.PutFile(nil, &ret, policy.Token(mac), key, localPath, nil)
log.Printf("ret : %+v", ret)
return err
}
开发者ID:gavinzhs,项目名称:testgo,代码行数:10,代码来源:qiniu.go
示例11: handleUpload
func handleUpload(w http.ResponseWriter, req *http.Request) {
policy := rs.PutPolicy{
Scope: BUCKET,
EndUser: "userId",
SaveKey: "$(sha1)",
}
token := policy.Token(nil)
log.Println("token:", token)
uploadForm := fmt.Sprintf(uploadFormFmt, token)
w.Write([]byte(uploadForm))
}
开发者ID:avivaxrq,项目名称:PiliWebTest,代码行数:11,代码来源:gosdk.go
示例12: main
func main() {
ACCESS_KEY = gopher.Config.QiniuAccessKey
SECRET_KEY = gopher.Config.QiniuSecretKey
extra := &qiniu_io.PutExtra{
Bucket: "gopher",
MimeType: "",
CustomMeta: "",
CallbackParams: "",
}
var policy = rs.PutPolicy{
Scope: "gopher",
}
c := gopher.DB.C("users")
var users []gopher.User
c.Find(nil).All(&users)
for _, user := range users {
url := webhelpers.Gravatar(user.Email, 256)
resp, err := http.Get(url)
if err != nil {
fmt.Println("get gravatar image error:", url, err.Error())
return
}
filename := strings.Replace(uuid.NewUUID().String(), "-", "", -1) + ".jpg"
body, _ := ioutil.ReadAll(resp.Body)
h := md5.New()
h.Write(body)
md5Str := fmt.Sprintf("%x", h.Sum(nil))
if md5Str != "ac83818c6d5b6aca4b6f796b6d3cb338" {
// 不是默认头像,上传
key := "avatar/" + filename
ret := new(qiniu_io.PutRet)
buf := bytes.NewBuffer(body)
err = qiniu_io.Put(nil, ret, policy.Token(), key, buf, extra)
if err == nil {
c.Update(bson.M{"_id": user.Id_}, bson.M{"$set": bson.M{"avatar": filename}})
fmt.Printf("upload %s's avatar success: %s\n", user.Email, filename)
} else {
fmt.Printf("upload %s' avatar error: %s\n", user.Email, err.Error())
}
}
resp.Body.Close()
}
}
开发者ID:hjqhezgh,项目名称:gopher,代码行数:53,代码来源:gravatar2qiniu.go
示例13: GetToken
func GetToken() (string, string) {
key := uuid.NewV4().String()
putPolicy := rs.PutPolicy{
Scope: g_bucket_name + ":" + key,
CallbackUrl: CALLBACK_URL,
CallbackBody: g_callback_body,
ReturnUrl: g_return_url,
ReturnBody: g_return_body,
}
return putPolicy.Token(nil), key
}
开发者ID:wxaxiaoyao,项目名称:linux,代码行数:12,代码来源:qiniu.go
示例14: qiniuUploadImage
func qiniuUploadImage(file *multipart.File, fileName string) (error, qio.PutRet) {
var ret qio.PutRet
var policy = rs.PutPolicy{
Scope: models.QiniuScope,
}
err := qio.Put(nil, &ret, policy.Token(nil), fileName, *file, nil)
if err != nil {
revel.ERROR.Println("io.Put failed:", err)
}
return err, ret
}
开发者ID:zeuson,项目名称:gorevel,代码行数:12,代码来源:application.go
示例15: uptoken
func uptoken(bucketName string) string {
putPolicy := rs.PutPolicy{
Scope: bucketName,
//CallbackUrl: callbackUrl,
//CallbackBody:callbackBody,
//ReturnUrl: returnUrl,
//ReturnBody: returnBody,
//AsyncOps: asyncOps,
//EndUser: endUser,
//Expires: expires,
}
return putPolicy.Token(mac)
}
开发者ID:sugeladi,项目名称:goWeb,代码行数:13,代码来源:qiniu.go
示例16: getInfo
func getInfo(w http.ResponseWriter, r *http.Request) {
userInfo := make(map[string]string)
policy := rs.PutPolicy{
Scope: BUCKET,
EndUser: "userId",
SaveKey: "$(sha1)",
}
token := policy.Token(nil)
userInfo["token"] = token
s := strings.Split(r.RemoteAddr, ":")
s[0] = "58.20.0.17"
userInfo["ip"] = s[0]
resp, _ := http.Get("http://ip.taobao.com/service/getIpInfo.php?ip=" + s[0])
defer resp.Body.Close()
by, _ := ioutil.ReadAll(resp.Body)
var ret map[string]interface{}
json.Unmarshal(by, &ret)
var data = ret["data"]
dataMap, ok := data.(map[string]interface{})
if ok {
var country = dataMap["country"]
countryInfo, ok := country.(string)
if ok {
userInfo["country"] = countryInfo
}
var region = dataMap["region"]
regionInfo, ok := region.(string)
if ok {
userInfo["region"] = regionInfo
}
var city = dataMap["city"]
cityInfo, ok := city.(string)
if ok {
userInfo["city"] = cityInfo
}
var isp = dataMap["isp"]
ispInfo, ok := isp.(string)
if ok {
userInfo["isp"] = ispInfo
}
}
for _, v := range r.Header["User-Agent"] {
userInfo["useragent"] = v
}
getInfoTmpl.ExecuteTemplate(w, "getinfo", userInfo)
}
开发者ID:avivaxrq,项目名称:PiliWebTest,代码行数:50,代码来源:webtest1.go
示例17: uptoken
//GET upload access token
func uptoken(bucketName string) string {
putPolicy := rs.PutPolicy{
Scope: bucketName,
//CallbackUrl: "127.0.0.1",
//CallbackBody:callbackBody,
//ReturnUrl: "127.0.0.1",
//ReturnBody: returnBody,
//AsyncOps: asyncOps,
//EndUser: endUser,
//Expires: expires,
PersistentOps: "vframe/jpg/offset/1|saveas/bmVlZGthbmU6MTN2Mg==",
}
return putPolicy.Token(nil)
}
开发者ID:needkane,项目名称:qiniu,代码行数:15,代码来源:main.go
示例18: UploadFile
func UploadFile(localFile string, destName string) (addr string, err error) {
policy := new(rs.PutPolicy)
policy.Scope = Bulket
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://" + Bulket + ".qiniudn.com/" + destName
return
}
开发者ID:matm,项目名称:gobuild,代码行数:14,代码来源:upload.go
示例19: uptoken
func uptoken(bucketName string, uid string) string {
//body := "x:uid=" + uid + "&key=$(etag)&size=$(fsize)" // + "&gentime=" + string(time.Now().Unix())
body := "uid=$(x:uid)&audiotitle=$(x:audiotitle)&key=$(etag)&size=$(fsize)" + "&gentime=" + string(time.Now().Unix())
putPolicy := rs.PutPolicy{
Scope: bucketName,
CallbackUrl: "http://www.oohoohoo.com/recqiniu?", //http://<your domain>/recqiniu
CallbackBody: body, //gae body eg:test=$(x:test)&key=$(etag)&size=$(fsize)&uid=$(endUser)
//ReturnUrl: returnUrl,
//ReturnBody: returnBody,
//AsyncOps: asyncOps,
EndUser: uid, //uid
Expires: 3600 * 24 * 7, // 1week?
}
return putPolicy.Token(nil)
}
开发者ID:restaurantt,项目名称:haha,代码行数:15,代码来源:myoohoohoo2.go
示例20: 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
ACCESS_KEY = Config.QiniuAccessKey
SECRET_KEY = Config.QiniuSecretKey
key := "avatar/" + filename
ret := new(qiniu_io.PutRet)
var policy = rs.PutPolicy{
Scope: "gopher",
}
err = qiniu_io.Put(
nil,
ret,
policy.Token(nil),
key,
file,
nil,
)
if err != nil {
return "", err
}
return filename, nil
}
开发者ID:hello-kukoo,项目名称:gopher,代码行数:48,代码来源:account.go
注:本文中的github.com/qiniu/api/rs.PutPolicy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论