Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
4935a06b
Commit
4935a06b
authored
Dec 13, 2024
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
11
parent
fc8c509a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
10 deletions
+21
-10
Config.cs
Mall.Common/Config.cs
+1
-0
OssService.cs
Mall.ThirdCore/Oss/OssService.cs
+2
-2
TencentOss.cs
Mall.ThirdCore/Oss/TencentOss.cs
+11
-5
FileController.cs
Mall.WebApi/Controllers/File/FileController.cs
+2
-1
appsettings.json
Mall.WebApi/appsettings.json
+3
-1
UploadHelper.cs
TestCore/UploadHelper.cs
+2
-1
No files found.
Mall.Common/Config.cs
View file @
4935a06b
...
...
@@ -838,6 +838,7 @@ namespace Mall.Common
ossObj
[
"accessKeyId"
]
=
ReadConfigKey
(
"tencentOSS"
,
"accessKeyId"
);
ossObj
[
"accessKeySecret"
]
=
ReadConfigKey
(
"tencentOSS"
,
"accessKeySecret"
);
ossObj
[
"domain"
]
=
ReadConfigKey
(
"tencentOSS"
,
"domain"
);
ossObj
[
"fileStoragePath"
]
=
ReadConfigKey
(
"tencentOSS"
,
"fileStoragePath"
);
return
ossObj
;
}
}
...
...
Mall.ThirdCore/Oss/OssService.cs
View file @
4935a06b
...
...
@@ -8,9 +8,9 @@ namespace Mall.ThirdCore.Oss
/// 创建上传实例
/// </summary>
/// <returns></returns>
public
static
IOssService
GetTencent
(
string
endpoint
=
null
,
string
accessKeyId
=
null
,
string
accessKeySecret
=
null
,
string
bucketName
=
null
)
public
static
IOssService
GetTencent
(
string
endpoint
=
null
,
string
accessKeyId
=
null
,
string
accessKeySecret
=
null
,
string
bucketName
=
null
,
string
fileStoragePath
=
null
)
{
return
TencentOss
.
Instance
(
endpoint
,
accessKeyId
,
accessKeySecret
,
bucketName
);
return
TencentOss
.
Instance
(
endpoint
,
accessKeyId
,
accessKeySecret
,
bucketName
,
fileStoragePath
);
}
/// <summary>
...
...
Mall.ThirdCore/Oss/TencentOss.cs
View file @
4935a06b
...
...
@@ -20,6 +20,10 @@ namespace Mall.ThirdCore.Oss
private
string
accessKeyId
=
""
;
private
string
accessKeySecret
=
""
;
private
string
bucketName
=
""
;
/// <summary>
/// 文件存储位置
/// </summary>
private
string
fileStoragePath
=
""
;
/// <summary>
/// 构造函数
...
...
@@ -28,25 +32,28 @@ namespace Mall.ThirdCore.Oss
/// <param name="accessKeyId"></param>
/// <param name="accessKeySecret"></param>
/// <param name="bucketName"></param>
public
TencentOss
(
string
endpoint
,
string
accessKeyId
,
string
accessKeySecret
,
string
bucketName
)
/// <param name="fileStoragePath">文件存储位置</param>
public
TencentOss
(
string
endpoint
,
string
accessKeyId
,
string
accessKeySecret
,
string
bucketName
,
string
fileStoragePath
)
{
this
.
endpoint
=
endpoint
;
this
.
accessKeyId
=
accessKeyId
;
this
.
accessKeySecret
=
accessKeySecret
;
this
.
bucketName
=
bucketName
;
this
.
fileStoragePath
=
fileStoragePath
;
}
/// <summary>
/// 创建实例
/// </summary>
/// <returns></returns>
public
static
TencentOss
Instance
(
string
endpoint
,
string
accessKeyId
,
string
accessKeySecret
,
string
bucketName
)
public
static
TencentOss
Instance
(
string
endpoint
,
string
accessKeyId
,
string
accessKeySecret
,
string
bucketName
,
string
fileStoragePath
)
{
endpoint
??=
"ap-chengdu"
;
accessKeyId
??=
"AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd"
;
accessKeySecret
??=
"PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob"
;
bucketName
??=
"viitto-1301420277"
;
return
new
TencentOss
(
endpoint
,
accessKeyId
,
accessKeySecret
,
bucketName
);
fileStoragePath
??=
"/SaleBefore/Goods/"
;
return
new
TencentOss
(
endpoint
,
accessKeyId
,
accessKeySecret
,
bucketName
,
fileStoragePath
);
}
/// <summary>
...
...
@@ -76,8 +83,7 @@ namespace Mall.ThirdCore.Oss
{
string
fileExtention
=
System
.
IO
.
Path
.
GetExtension
(
filePath
);
string
bucket
=
this
.
bucketName
;
//存储桶,格式:BucketName-APPID
string
key
=
@"/SaleBefore/Goods/"
+
DateTime
.
Now
.
Ticks
.
ToString
()
+
fileExtention
;
//对象在存储桶中的位置,即称对象键
string
key
=
fileStoragePath
+
DateTime
.
Now
.
Ticks
.
ToString
()
+
fileExtention
;
//对象在存储桶中的位置,即称对象键
PutObjectRequest
request
=
new
PutObjectRequest
(
bucket
,
key
,
filePath
);
//设置签名有效时长
request
.
SetSign
(
TimeUtils
.
GetCurrentTime
(
TimeUnit
.
SECONDS
),
600
);
...
...
Mall.WebApi/Controllers/File/FileController.cs
View file @
4935a06b
...
...
@@ -172,8 +172,9 @@ namespace Mall.WebApi.Controllers.File
{
fileModel
.
Bucket
=
Common
.
Config
.
TencentOSS
.
GetStringValue
(
"bucket"
);
}
string
fileStorePath
=
Common
.
Config
.
TencentOSS
.
GetStringValue
(
"fileStoragePath"
);
IsDefault
=
false
;
IOssService
ossService
=
OssService
.
GetTencent
(
fileModel
.
Region
,
fileModel
.
SecretId
,
fileModel
.
SecretKey
,
fileModel
.
Bucket
);
IOssService
ossService
=
OssService
.
GetTencent
(
fileModel
.
Region
,
fileModel
.
SecretId
,
fileModel
.
SecretKey
,
fileModel
.
Bucket
,
fileStorePath
);
OssResult
result
=
ossService
.
UploadFile
(
path_server
,
null
);
try
{
...
...
Mall.WebApi/appsettings.json
View file @
4935a06b
...
...
@@ -114,7 +114,9 @@
"bucket"
:
"viitto-1301420277"
,
"accessKeyId"
:
"AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd"
,
"accessKeySecret"
:
"PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob"
,
"domain"
:
"https://viitto-1301420277.cos.ap-chengdu.myqcloud.com"
"domain"
:
"https://viitto-1301420277.cos.ap-chengdu.myqcloud.com"
,
//腾讯云文件存储路径
"fileStoragePath"
:
"/SaleBefore/Goods/"
},
//阿里OSS配置
"aliOSS"
:
{
...
...
TestCore/UploadHelper.cs
View file @
4935a06b
...
...
@@ -20,7 +20,8 @@ namespace TestCore
string
SecretId
=
"AKIDDPnbIzi8C1eqEOPP8dw6MNAg9H9ldDKd"
;
string
SecretKey
=
"PdcLtOjslUzNFYdU4OSI1fKtdHpFT2Ob"
;
string
Bucket
=
"viitto-1301420277"
;
IOssService
ossService
=
OssService
.
GetTencent
(
Region
,
SecretId
,
SecretKey
,
Bucket
);
string
fileStoragePath
=
string
.
Format
(
"/{0}Mall/SaleBefore/Goods/"
,
DateTime
.
Now
.
ToString
(
"yyyy"
));
IOssService
ossService
=
OssService
.
GetTencent
(
Region
,
SecretId
,
SecretKey
,
Bucket
,
fileStoragePath
);
OssResult
result
=
ossService
.
UploadFile
(
filePath
,
null
);
return
result
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment