upload 上传 签名 直接上传都可以
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/check"
|
||||
"fusenapi/utils/format"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
@@ -69,50 +68,27 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.RequestUploadFileB
|
||||
req.File.Filename,
|
||||
))
|
||||
|
||||
var bucketName *string
|
||||
switch category {
|
||||
case format.TCategoryRenderMegre:
|
||||
|
||||
lifecycleConfiguration := &s3.BucketLifecycleConfiguration{
|
||||
Rules: []*s3.LifecycleRule{
|
||||
{
|
||||
Status: aws.String("Enabled"),
|
||||
// Status: aws.String("Disabled"),
|
||||
Filter: &s3.LifecycleRuleFilter{
|
||||
Prefix: ObjectKey,
|
||||
},
|
||||
Expiration: &s3.LifecycleExpiration{
|
||||
// Date: aws.Time(time.Now().UTC().Add(time.Minute)),
|
||||
Days: aws.Int64(1), // 设置过期天数,例如:30天
|
||||
},
|
||||
// ID: aws.String("ExpireAfter01Days"), // 设置规则的唯一标识符
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
s3req, _ = svc.PutBucketLifecycleConfigurationRequest(
|
||||
&s3.PutBucketLifecycleConfigurationInput{
|
||||
Bucket: basic.StorageBucketName,
|
||||
LifecycleConfiguration: lifecycleConfiguration,
|
||||
},
|
||||
)
|
||||
bucketName = basic.TempfileBucketName
|
||||
default:
|
||||
s3req, _ = svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: basic.StorageBucketName,
|
||||
Key: ObjectKey,
|
||||
},
|
||||
)
|
||||
|
||||
bucketName = basic.StorageBucketName
|
||||
}
|
||||
|
||||
s3req, _ = svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: bucketName,
|
||||
Key: ObjectKey,
|
||||
},
|
||||
)
|
||||
s3req.SetBufferBody(req.File.Data)
|
||||
err := s3req.Send()
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeS3PutObjectRequestErr)
|
||||
}
|
||||
log.Println(s3req.HTTPRequest.URL)
|
||||
|
||||
logx.Info(s3req.HTTPRequest.URL.String())
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"upload_url": s3req.HTTPRequest.URL.String(),
|
||||
})
|
||||
|
||||
@@ -61,18 +61,28 @@ func (l *UploadFileFrontendLogic) UploadFileFrontend(req *types.RequestUploadFil
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
category := format.TypeCategory(req.Category)
|
||||
ObjectKey := aws.String(format.FormatS3KeyName(
|
||||
keytype,
|
||||
uid,
|
||||
now,
|
||||
l.svcCtx.Config.Env,
|
||||
format.TypeCategory(req.Category),
|
||||
req.FileName,
|
||||
))
|
||||
|
||||
var bucketName *string
|
||||
switch category {
|
||||
case format.TCategoryRenderMegre:
|
||||
bucketName = basic.TempfileBucketName
|
||||
default:
|
||||
bucketName = basic.StorageBucketName
|
||||
}
|
||||
|
||||
s3req, _ := svc.PutObjectRequest(
|
||||
&s3.PutObjectInput{
|
||||
Bucket: aws.String("storage.fusenpack.com"),
|
||||
Key: aws.String(format.FormatS3KeyName(
|
||||
keytype,
|
||||
uid,
|
||||
now,
|
||||
l.svcCtx.Config.Env,
|
||||
format.TypeCategory(req.Category),
|
||||
req.FileName,
|
||||
)),
|
||||
Bucket: bucketName,
|
||||
Key: ObjectKey,
|
||||
ContentLength: aws.Int64(req.FileSize),
|
||||
},
|
||||
)
|
||||
@@ -81,7 +91,6 @@ func (l *UploadFileFrontendLogic) UploadFileFrontend(req *types.RequestUploadFil
|
||||
if err != nil {
|
||||
return resp.SetStatus(basic.CodeS3PutObjectRequestErr)
|
||||
}
|
||||
// log.Println(uri)
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||
"upload_url": uri,
|
||||
|
||||
Reference in New Issue
Block a user