新增阿里云OSS上传文件逻辑
This commit is contained in:
parent
e806342959
commit
138b0d0c4e
@ -25,4 +25,12 @@ type Config struct {
|
|||||||
Version string
|
Version string
|
||||||
Urls []string
|
Urls []string
|
||||||
}
|
}
|
||||||
|
AliyunOSS struct {
|
||||||
|
Endpoint string `json:"endpoint"`
|
||||||
|
AccessKeyId string `json:"access_key_id"`
|
||||||
|
AccessKeySecret string `json:"access_key_secret"`
|
||||||
|
BucketName string `json:"bucket_name"`
|
||||||
|
BucketUrl string `json:"bucket_url"`
|
||||||
|
BasePath string `json:"base_path"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
@ -107,7 +108,19 @@ func (l *UploadFileBackendLogic) UploadFileBackend(req *types.UploadFileBackendR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 是否备份--异步任务
|
// 是否备份--异步任务
|
||||||
|
if req.BackupType != "" {
|
||||||
|
time.AfterFunc(time.Second*1, func() {
|
||||||
|
upload.UploadType = "oss"
|
||||||
|
upload.AliyunOSS.Endpoint = l.svcCtx.Config.AliyunOSS.Endpoint
|
||||||
|
upload.AliyunOSS.AccessKeyId = l.svcCtx.Config.AliyunOSS.AccessKeyId
|
||||||
|
upload.AliyunOSS.AccessKeySecret = l.svcCtx.Config.AliyunOSS.AccessKeySecret
|
||||||
|
upload.AliyunOSS.BucketName = l.svcCtx.Config.AliyunOSS.BucketName
|
||||||
|
upload.AliyunOSS.BucketUrl = l.svcCtx.Config.AliyunOSS.BucketUrl
|
||||||
|
upload.AliyunOSS.BasePath = l.svcCtx.Config.AliyunOSS.BasePath
|
||||||
|
|
||||||
|
err = upload.UploadFileByUrl(resourceId, uploadRes.ResourceUrl)
|
||||||
|
})
|
||||||
|
}
|
||||||
// 返回成功的响应和上传URL
|
// 返回成功的响应和上传URL
|
||||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
"upload_data": UploadUrl{
|
"upload_data": UploadUrl{
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/file"
|
"fusenapi/utils/file"
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
|
"time"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
@ -88,6 +89,21 @@ func (l *UploadFileBaseLogic) UploadFileBase(req *types.UploadFileBaseReq, useri
|
|||||||
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
return resp.SetStatus(basic.CodeFileUploadErr, "upload file failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 是否备份--异步任务
|
||||||
|
if req.BackupType != "" {
|
||||||
|
time.AfterFunc(time.Second*1, func() {
|
||||||
|
upload.UploadType = "oss"
|
||||||
|
upload.AliyunOSS.Endpoint = l.svcCtx.Config.AliyunOSS.Endpoint
|
||||||
|
upload.AliyunOSS.AccessKeyId = l.svcCtx.Config.AliyunOSS.AccessKeyId
|
||||||
|
upload.AliyunOSS.AccessKeySecret = l.svcCtx.Config.AliyunOSS.AccessKeySecret
|
||||||
|
upload.AliyunOSS.BucketName = l.svcCtx.Config.AliyunOSS.BucketName
|
||||||
|
upload.AliyunOSS.BucketUrl = l.svcCtx.Config.AliyunOSS.BucketUrl
|
||||||
|
upload.AliyunOSS.BasePath = l.svcCtx.Config.AliyunOSS.BasePath
|
||||||
|
|
||||||
|
err = upload.UploadFileByUrl(resourceId, uploadRes.ResourceUrl)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 返回成功的响应和上传URL
|
// 返回成功的响应和上传URL
|
||||||
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
"upload_data": UploadUrl{
|
"upload_data": UploadUrl{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user