animeic 1 年之前
父节点
当前提交
e5d442c6cb
共有 5 个文件被更改,包括 151 次插入169 次删除
  1. 27 162
      baishuihu/api/upload.go
  2. 14 6
      baishuihu/app.yaml
  3. 14 1
      baishuihu/go.mod
  4. 40 0
      baishuihu/go.sum
  5. 56 0
      baishuihu/index.html

+ 27 - 162
baishuihu/api/upload.go

@@ -1,181 +1,46 @@
 package api
 
 import (
-	"baishuihu/conf"
-	"errors"
-	"fmt"
-	"io"
-	"math/rand"
-	"os"
-	"path"
-	"strings"
-	"time"
-	"unsafe"
-
+	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
+	sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
+	util "github.com/alibabacloud-go/tea-utils/v2/service"
+	"github.com/alibabacloud-go/tea/tea"
 	"github.com/gin-gonic/gin"
-	"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
-)
-
-const (
-	letterIdBits = 6
-	letterIdMask = 1<<letterIdBits - 1
-	letterIdMax  = 63 / letterIdBits
-	letters      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
 )
 
-var src = rand.NewSource(time.Now().UnixNano())
-
 func Upload(r *GinRouter) {
-	r.POST("upload/image", UploadImage)
-	r.POST("upload/file", UploadFile)
 	r.POST("upload/policy", UploadPolicy)
 }
 
-func UploadPolicy(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	return ServiceObsUploadPolicy(c, apictx)
-}
-
-// 管理后台上传文件
-func ServiceObsUploadPolicy(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-
-	body := struct {
-		Key string
-	}{}
-
-	err := c.ShouldBindJSON(&body)
-	if err != nil {
-		return nil, NewError("参数解析错误!")
-	}
-	if len(body.Key) < 1 {
-		return nil, NewError("上传文件的key不能为空")
-	}
-	client, err := CreateObsClient()
-	if err != nil {
-		return nil, NewError("创建ObsClient 失败!")
-	}
-	defer func() {
-		client.Close()
-	}()
-	bucketName := apictx.Svc.Conf.Obs.Bucket
-
-	result, err := client.CreateBrowserBasedSignature(&obs.CreateBrowserBasedSignatureInput{
-		Bucket:  bucketName,
-		Key:     body.Key,
-		Expires: 600,
-		FormParams: map[string]string{
-			"x-obs-acl": "public-read",
-		},
-	})
-
-	if err != nil {
-		return nil, NewLogWithError(err)
-	}
-	obsConf := conf.AppConfig.Obs
-	out := map[string]interface{}{
-		"accessKeyId":  obsConf.AccessKeyId,
-		"originPolicy": result.OriginPolicy,
-		"policy":       result.Policy,
-		"signature":    result.Signature,
-		"host":         fmt.Sprintf("https://%s.%s", bucketName, obsConf.Endpoint),
-		"key":          body.Key,
-		"saveType":     "obs",
-	}
-	return out, nil
-}
-
-func CreateObsClient() (*obs.ObsClient, error) {
-	obsConf := conf.AppConfig.Obs
-	return obs.New(obsConf.AccessKeyId, obsConf.SecrateKey, obsConf.Endpoint)
-}
-
-// 本地上传图片
-func UploadFile(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	handle, err := c.FormFile("file")
-	// 上传图像接口
-	if err != nil {
-		return nil, err
-	}
-	uploadFile, err := handle.Open()
-	if err != nil {
-		return nil, err
-	}
-	if handle.Size > 500<<20 {
-		return nil, errors.New("最大支持单文件上传大小为50M")
-	}
-
-	saveFile, err := os.OpenFile(fmt.Sprintf("files/%s", handle.Filename), os.O_WRONLY|os.O_CREATE, 0666)
-	if err != nil {
-		return nil, err
-	}
-	io.Copy(saveFile, uploadFile)
-	defer uploadFile.Close()
-	defer saveFile.Close()
+const (
+	STS_ADDR = "sts.cn-chengdu.aliyuncs.com"
+	ROLE_ARN = "acs:ram::1187995103897985:role/ramoss"
+	//自定义
+	ROLE_SESSION_NAME = "baishuihu-admin"
+)
 
-	// http://127.0.0.1:8101/public/
-	out := map[string]string{
-		"url":  fmt.Sprintf("%s/files/%s", conf.AppConfig.PublicBaseUrl, handle.Filename),
-		"path": fmt.Sprintf("files/%s", handle.Filename),
+func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *sts20150401.Client, _err error) {
+	config := &openapi.Config{
+		AccessKeyId:     accessKeyId,
+		AccessKeySecret: accessKeySecret,
 	}
-	return out, nil
+	// Endpoint 请参考 https://api.aliyun.com/product/Sts
+	config.Endpoint = tea.String(STS_ADDR)
+	_result = &sts20150401.Client{}
+	_result, _err = sts20150401.NewClient(config)
+	return _result, _err
 }
 
-// 本地上传图片
-func UploadImage(c *gin.Context, apictx *ApiSession) (interface{}, error) {
-	handle, err := c.FormFile("image")
-	// 上传图像接口
-	if err != nil {
-		return nil, err
-	}
-	uploadFile, err := handle.Open()
-	if err != nil {
-		return nil, err
-	}
-
-	ext1 := strings.ToLower(path.Ext(handle.Filename))
-	ext := strings.ToLower(ext1)
-	limits := []string{".jpg", ".png", ".jpeg"}
-	isAllow := false
-	for _, limit := range limits {
-		if ext == limit {
-			isAllow = true
-			break
-		}
-	}
-	if !isAllow {
-		return nil, errors.New("只支持jpg/jpeg/png图片上传")
-	}
-
-	// 保存图片
-	os.Mkdir("images/", 0777)
-	pathFileName := fmt.Sprintf("%s_%s%s", randName(8), time.Now().Format("20060102"), ext)
-	saveFile, err := os.OpenFile(fmt.Sprintf("images/%s", pathFileName), os.O_WRONLY|os.O_CREATE, 0666)
+func UploadPolicy(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	client, err := CreateClient(tea.String(apictx.Svc.Conf.Obs.AccessKeyId), tea.String(apictx.Svc.Conf.Obs.SecrateKey))
 	if err != nil {
 		return nil, err
 	}
-	io.Copy(saveFile, uploadFile)
-	defer uploadFile.Close()
-	defer saveFile.Close()
-
-	// http://127.0.0.1:8101/public/
-	out := map[string]string{
-		"url":  fmt.Sprintf("%s/images/%s", conf.AppConfig.PublicBaseUrl, pathFileName),
-		"path": fmt.Sprintf("images/%s", pathFileName),
-	}
-	return out, nil
-}
-
-func randName(n int) string {
-	b := make([]byte, n)
-	for i, cache, remain := n-1, src.Int63(), letterIdMax; i >= 0; {
-		if remain == 0 {
-			cache, remain = src.Int63(), letterIdMax
-		}
-		if idx := int(cache & letterIdMask); idx < len(letters) {
-			b[i] = letters[idx]
-			i--
-		}
-		cache >>= letterIdBits
-		remain--
+	assumeRoleRequest := &sts20150401.AssumeRoleRequest{
+		RoleArn:         tea.String(ROLE_ARN),
+		RoleSessionName: tea.String(ROLE_SESSION_NAME),
 	}
-	return *(*string)(unsafe.Pointer(&b))
+	runtime := &util.RuntimeOptions{}
+	result, err := client.AssumeRoleWithOptions(assumeRoleRequest, runtime)
+	return result, err
 }

+ 14 - 6
baishuihu/app.yaml

@@ -27,16 +27,24 @@ log:
   serviceName: adhuaxi
 
 configer:
-  mongo: baishuihu-mongo
-  redis: baishuihu-redis
+  mongo: adxihua-mongo
+  redis: adxihua-redis
 
 publicBaseUrl: http://127.0.0.1:18091/public
 
+# 主账号
+# obs:
+#   bucket: baishuihu
+#   accessKeyId: LTAI5tC5uAPKWRQMyvwETRwf
+#   secrateKey: asiIuMCXC6mmVf1q52jzkQvF62mv3w
+#   endpoint: oss-cn-chengdu.aliyuncs.com
+
+# ossaccount
 obs:
-  bucket: sku3d-test
-  accessKeyId: "RA1D7CFVCVKUFX1FHHPB"
-  secrateKey: "cDrR2NgAF2KaA4MRkcK19r93P3P6hLKOPhHvPu9p"
-  endpoint: "obs.cn-east-3.myhuaweicloud.com"
+  bucket: baishuihu
+  accessKeyId: LTAI5t7HEYvgfkXxvt6PzuPK
+  secrateKey: STAbtmqRM3iUYIn8zlu5M8kIaNfdCr
+  endpoint: oss-cn-chengdu.aliyuncs.com
     
 
 

+ 14 - 1
baishuihu/go.mod

@@ -3,6 +3,11 @@ module baishuihu
 go 1.19
 
 require (
+	github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.2
+	github.com/alibabacloud-go/sts-20150401/v2 v2.0.1
+	github.com/alibabacloud-go/tea v1.1.19
+	github.com/alibabacloud-go/tea-utils/v2 v2.0.1
+	github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible
 	github.com/appleboy/gin-jwt/v2 v2.8.0
 	github.com/gin-contrib/cors v1.4.0
 	github.com/gin-contrib/sessions v0.0.5
@@ -18,8 +23,16 @@ require (
 
 require (
 	github.com/StackExchange/wmi v1.2.1 // indirect
-	github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible // indirect
+	github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect
+	github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
+	github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect
+	github.com/alibabacloud-go/openapi-util v0.1.0 // indirect
+	github.com/alibabacloud-go/tea-utils v1.3.1 // indirect
+	github.com/alibabacloud-go/tea-xml v1.1.2 // indirect
+	github.com/aliyun/credentials-go v1.1.2 // indirect
+	github.com/clbanning/mxj/v2 v2.5.5 // indirect
 	github.com/go-ole/go-ole v1.2.5 // indirect
+	github.com/tjfoc/gmsm v1.3.2 // indirect
 	golang.org/x/time v0.3.0 // indirect
 )
 

+ 40 - 0
baishuihu/go.sum

@@ -121,8 +121,36 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
 github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
 github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0=
 github.com/alexflint/go-filemutex v1.1.0/go.mod h1:7P4iRhttt/nUvUOrYIhcpMzv2G6CY9UnI16Z+UJqRyk=
+github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJnOkZsene9olVspKmkX5A2YBEo=
+github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
+github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.2 h1:2kR1YkvQloHUstmPcG0Sjk24zTKbza7izzJfJNwBFSs=
+github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.2/go.mod h1:5JHVmnHvGzR2wNdgaW1zDLQG8kOC4Uec8ubkMogW7OQ=
+github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50=
+github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
+github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
+github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
+github.com/alibabacloud-go/openapi-util v0.0.11/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
+github.com/alibabacloud-go/openapi-util v0.1.0 h1:0z75cIULkDrdEhkLWgi9tnLe+KhAFE/r5Pb3312/eAY=
+github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws=
+github.com/alibabacloud-go/sts-20150401/v2 v2.0.1 h1:CevZp0VdG7Q+1J3qwNj+JL7ztKxsL27+tknbdTK9Y6M=
+github.com/alibabacloud-go/sts-20150401/v2 v2.0.1/go.mod h1:8wJW1xC4mVcdRXzOvWJYfCCxmvFzZ0VB9iilVjBeWBc=
+github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
+github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
+github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4=
+github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
+github.com/alibabacloud-go/tea v1.1.19 h1:Xroq0M+pr0mC834Djj3Fl4ZA8+GGoA0i7aWse1vmgf4=
+github.com/alibabacloud-go/tea v1.1.19/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
+github.com/alibabacloud-go/tea-utils v1.3.1 h1:iWQeRzRheqCMuiF3+XkfybB3kTgUXkXX+JMrqfLeB2I=
+github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE=
+github.com/alibabacloud-go/tea-utils/v2 v2.0.0/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4=
+github.com/alibabacloud-go/tea-utils/v2 v2.0.1 h1:K6kwgo+UiYx+/kr6CO0PN5ACZDzE3nnn9d77215AkTs=
+github.com/alibabacloud-go/tea-utils/v2 v2.0.1/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4=
+github.com/alibabacloud-go/tea-xml v1.1.2 h1:oLxa7JUXm2EDFzMg+7oRsYc+kutgCVwm+bZlhhmvW5M=
+github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
 github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible h1:Sg/2xHwDrioHpxTN6WMiwbXTpUEinBpHsN7mG21Rc2k=
 github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
+github.com/aliyun/credentials-go v1.1.2 h1:qU1vwGIBb3UJ8BwunHDRFtAhS6jnQLnde/yk0+Ih2GY=
+github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
 github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
 github.com/apache/arrow/go/arrow v0.0.0-20210818145353-234c94e4ce64/go.mod h1:2qMFB56yOP3KzkB3PbYZ4AlUFg3a88F67TIx5lB/WwY=
 github.com/apache/arrow/go/arrow v0.0.0-20211013220434-5962184e7a30/go.mod h1:Q7yQnSMnLvcXlZ8RV+jwz/6y1rQTqbX6C82SndT52Zs=
@@ -210,6 +238,8 @@ github.com/cilium/ebpf v0.2.0/go.mod h1:To2CFviqOWL/M0gIMsvSMlqe7em/l1ALkX1PyjrX
 github.com/cilium/ebpf v0.4.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
 github.com/cilium/ebpf v0.6.2/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs=
 github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA=
+github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E=
+github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
 github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
 github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
@@ -645,6 +675,7 @@ github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2c
 github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA=
 github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
+github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
 github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
@@ -1091,6 +1122,7 @@ github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
 github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
 github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
+github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/snowflakedb/gosnowflake v1.6.3/go.mod h1:6hLajn6yxuJ4xUHZegMekpq9rnQbGJ7TMwXjgTmA6lg=
@@ -1154,6 +1186,8 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
 github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
 github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
+github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
+github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -1199,6 +1233,7 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqTosly
 github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
 github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
@@ -1288,8 +1323,10 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
 golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
+golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
@@ -1513,6 +1550,7 @@ golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7w
 golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -1666,6 +1704,7 @@ golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjs
 golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
 golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
+golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
 golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
@@ -1885,6 +1924,7 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKW
 gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
 gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
 gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
 gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
 gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=

+ 56 - 0
baishuihu/index.html

@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <title>Document</title>
+  </head>
+  <body>
+    <input id="file" type="file" />
+    <button id="upload">上传</button>
+    <script src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
+    <script>
+      const client = new OSS({
+        // yourRegion填写Bucket所在地域。以华东1(杭州)为例,yourRegion填写为oss-cn-hangzhou。
+        region: "oss-cn-chengdu",
+        // 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
+        accessKeyId: "STS.NTkTKPpiTB1NVdV7wEQH3wkD4",
+        accessKeySecret: "HT3aNHuN5EKYieU8ECZCpRh98GwJLz4dchpLtAEdTmUi",
+        // 从STS服务获取的安全令牌(SecurityToken)。
+        stsToken: "CAIS9AF1q6Ft5B2yfSjIr5feH/HknbZ19fOlVELn03cQXccfmK7v1jz2IHhMfHdoCeAet/s0lGpY5vYflqZ5Qp5eRVHFbdY155hS8AX5gX99Qw/sv9I+k5SANTW5KXyShb3/AYjQSNfaZY3eCTTtnTNyxr3XbCirW0ffX7SClZ9gaKZ8PGD6F00kYu1bPQx/ssQXGGLMPPK2SH7Qj3HXEVBjt3gX6wo9y9zmm53Du0uD1QWhmr5K9tSsGPX+MZkwZqUYesyuwel7epDG1CNt8BVQ/M909vccoW+Z5oHNWwAOuEXcY7qEr8cBNgZ8YbMhC0f/YkEOchsSGoABsc0y6cqEzBt1pRDRz1781lA4wOlFriMIqNN+raBhapzZ+uGd647DJFpnpm6GqXbY8gWD2EJ4k9eGYEuK7e4kFkCJH6+UUjyT4OVJPKJCUIjZaeJE86TbzcR3a6tw6yuOsV8Knk0r7vc2ngArFBn51XPm3wUKsYn8ZH5rhCDDv24gAA==",
+        // 填写Bucket名称。
+        bucket: "baishuihu",
+      });
+
+      // 从输入框获取file对象,例如<input type="file" id="file" />。
+      let data;
+      // 创建并填写Blob数据。
+      //const data = new Blob(['Hello OSS']);
+      // 创建并填写OSS Buffer内容。
+      //const data = new OSS.Buffer(['Hello OSS']);
+
+      const upload = document.getElementById("upload");
+
+      async function putObject(data) {
+        try {
+          // 填写Object完整路径。Object完整路径中不能包含Bucket名称。
+          // 您可以通过自定义文件名(例如exampleobject.txt)或文件完整路径(例如exampledir/exampleobject.txt)的形式实现将数据上传到当前Bucket或Bucket中的指定目录。
+          // data对象可以自定义为file对象、Blob数据或者OSS Buffer。
+          const options = {
+            meta: { temp: "demo" },
+            mime: "json",
+            headers: { "Content-Type": "text/plain" },
+          };
+          const result = await client.put("ACC/aaaa.png", data, options);
+          console.log(result);
+        } catch (e) {
+          console.log(e);
+        }
+      }
+
+      upload.addEventListener("click", () => {
+        const data = file.files[0];
+        putObject(data);
+      });
+    </script>
+  </body>
+</html>