|
@@ -168,54 +168,6 @@ func CommOss(c *gin.Context, args ImgReqUploadReq) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cfgMap := make(map[string]string, len(*sysCfgs)) |
|
|
|
|
|
for _, cfg := range *sysCfgs { |
|
|
|
|
|
cfgMap[cfg.Key] = cfg.Val |
|
|
|
|
|
} |
|
|
|
|
|
endpoint := cfgMap[enum2.AliyunOssEndpoint] |
|
|
|
|
|
bucketName := cfgMap[enum2.AliyunOssBucketName] |
|
|
|
|
|
ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme] |
|
|
|
|
|
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] |
|
|
|
|
|
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] |
|
|
|
|
|
|
|
|
|
|
|
// 创建OSSClient实例。 |
|
|
|
|
|
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 获取存储空间。 |
|
|
|
|
|
bucket, err := client.Bucket(bucketName) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
options := []oss.Option{ |
|
|
|
|
|
oss.ContentType(args.ContentType), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_AES_ENCODE, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
e.OutSuc(c, signedURL, nil) |
|
|
|
|
|
} |
|
|
|
|
|
func NewCommOss(c *gin.Context, args ImgReqUploadReq) { |
|
|
|
|
|
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) |
|
|
|
|
|
sysCfgs, err := sysCfgDb.SysCfgGetAll() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if sysCfgs == nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_CFG_CACHE, nil) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cfgMap := make(map[string]string, len(*sysCfgs)) |
|
|
cfgMap := make(map[string]string, len(*sysCfgs)) |
|
|
for _, cfg := range *sysCfgs { |
|
|
for _, cfg := range *sysCfgs { |
|
|
cfgMap[cfg.Key] = cfg.Val |
|
|
cfgMap[cfg.Key] = cfg.Val |
|
@@ -226,11 +178,9 @@ func NewCommOss(c *gin.Context, args ImgReqUploadReq) { |
|
|
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] |
|
|
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID] |
|
|
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] |
|
|
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret] |
|
|
if cfg.Prd { |
|
|
if cfg.Prd { |
|
|
accessKeyID = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID") |
|
|
|
|
|
accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET") |
|
|
|
|
|
|
|
|
accessKeyID = os.Getenv(enum2.AliyunOssAccessKeyID) |
|
|
|
|
|
accessKeySecret = os.Getenv(enum2.AliyunOssAccessKeySecret) |
|
|
} |
|
|
} |
|
|
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_ID>>>>>>>>", accessKeyID) |
|
|
|
|
|
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_SECRET>>>>>>>>", accessKeySecret) |
|
|
|
|
|
|
|
|
|
|
|
// 创建OSSClient实例。 |
|
|
// 创建OSSClient实例。 |
|
|
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) |
|
|
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret) |
|
|