作者 庄敏学

上传文件

... ... @@ -4,6 +4,7 @@ go 1.16
require (
github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible // indirect
github.com/beego/beego/v2 v2.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/disintegration/imaging v1.6.2
... ...
... ... @@ -16,6 +16,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
github.com/alicebob/miniredis v2.5.0+incompatible/go.mod h1:8HZjEj4yU0dwhYHky+DxYx+6BMjkBbe5ONFIF1MXffk=
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible h1:uuJIwCFhbZy+zdvLy5zrcIToPEQP0s5CFOZ0Zj03O/w=
github.com/aliyun/aliyun-oss-go-sdk v2.2.1+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
github.com/beanstalkd/go-beanstalk v0.1.0/go.mod h1:/G8YTyChOtpOArwLTQPY1CHB+i212+av35bkPXXj56Y=
github.com/beego/beego/v2 v2.0.1 h1:07a7Z0Ok5vbqyqh+q53sDPl9LdhKh0ZDy3gbyGrhFnE=
... ... @@ -484,6 +486,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
... ...
package constant
const OssAccessKey = "LTAI4Fz1LUBW2fXp6QWaJHRS"
const OssSecret = "aLZXwK8pgrs10Ws03qcN7NsrSXFVsg"
var OssBucket = "timeless-world"
const OssDomain = "http://timeless-world.oss-cn-shenzhen.aliyuncs.com"
\ No newline at end of file
... ...
package oss
import (
"bytes"
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/linmadan/egglib-go/utils/snowflake"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
)
var snow, _ = snowflake.NewIdWorker(1)
func UploadOss(data []byte) (string, error) {
client, err := oss.New("oss-cn-shenzhen.aliyuncs.com", constant.OssAccessKey, constant.OssSecret)
if err != nil {
return "", err
}
bucket, err := client.Bucket(constant.OssBucket)
if err != nil {
return "", err
}
fileId, err := snow.NextId()
if err != nil {
return "", err
}
fileName := "costs/" + fmt.Sprintf("%v", fileId)
err = bucket.PutObject(fileName, bytes.NewBuffer(data))
return constant.OssDomain +"/"+ fileName, err
}
\ No newline at end of file
... ...
package oss
import (
"fmt"
"io/ioutil"
"testing"
)
func TestOss(t *testing.T){
mBytes,_:=ioutil.ReadFile("./test.png")
result,err := UploadOss(mBytes)
fmt.Println(result,err)
}
\ No newline at end of file
... ...