提交 167186fa 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

混入日志包

上级 3c16f8a3
package support
import (
"bytes"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
"mime/multipart"
)
var accessKey string = "25j8dYBZ2wuiy0yhwShytjZDTX662b8xiFguwxzZ" // 你在七牛云的accessKey
var secretKey string = "pgdbqEsf7ooZh7W3xokP833h3dZ_VecFXPDeG5JY" // 你在七牛云的secretKey
var bucket string = "a303176530" // 你七牛云标准空间的名字
func Upload(file multipart.File) (err error, path string) {
putPolicy := storage.PutPolicy{
Scope: bucket,
}
mac := qbox.NewMac(accessKey, secretKey)
upToken := putPolicy.UploadToken(mac)
cfg := storage.Config{}
// 空间对应的机房
cfg.Zone = &storage.ZoneHuadong
// 是否使用https域名
cfg.UseHTTPS = false
// 上传是否使用CDN上传加速
cfg.UseCdnDomains = false
formUploader := storage.NewFormUploader(&cfg)
ret := storage.PutRet{}
putExtra := storage.PutExtra{
Params: map[string]string{
"x:name": "github logo",
},
}
data := []byte("hello, this is qiniu cloud")
dataLen := int64(len(data))
err := formUploader.Put(context.Background(), &ret, upToken, key, bytes.NewReader(data), dataLen, &putExtra)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(ret.Key, ret.Hash)
}
......@@ -14,6 +14,8 @@ require (
github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f
github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect
github.com/pkg/errors v0.8.1
github.com/qiniu/api.v7 v7.2.5+incompatible
github.com/qiniu/x v7.0.8+incompatible // indirect
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.2.0
......@@ -21,4 +23,5 @@ require (
github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.5.1
github.com/tebeka/strftime v0.1.3 // indirect
qiniupkg.com/x v7.0.8+incompatible // indirect
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册