Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-aliyun
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hqzhdj
cloud-aliyun
Commits
f7e15fdf
Commit
f7e15fdf
authored
Feb 18, 2025
by
阳浪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传
parent
e3890bda
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
19 deletions
+27
-19
cloud-aliyun-service/src/main/java/com/yizhi/aliyun/application/controller/FileUploadController.java
+7
-2
cloud-aliyun-service/src/main/java/com/yizhi/aliyun/application/controller/PolicyController.java
+20
-17
No files found.
cloud-aliyun-service/src/main/java/com/yizhi/aliyun/application/controller/FileUploadController.java
View file @
f7e15fdf
...
@@ -4,6 +4,7 @@ import com.yizhi.aliyun.application.util.PropertiesUtil;
...
@@ -4,6 +4,7 @@ import com.yizhi.aliyun.application.util.PropertiesUtil;
import
com.yizhi.core.application.file.util.MinioTools
;
import
com.yizhi.core.application.file.util.MinioTools
;
import
com.yizhi.util.application.domain.Response
;
import
com.yizhi.util.application.domain.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
...
@@ -22,14 +23,18 @@ public class FileUploadController {
...
@@ -22,14 +23,18 @@ public class FileUploadController {
@Autowired
@Autowired
PropertiesUtil
propertiesUtil
;
PropertiesUtil
propertiesUtil
;
@Value
(
"${pc.host.url}"
)
String
pcHostUrl
;
@PostMapping
(
"/upload"
)
@PostMapping
(
"/upload"
)
public
Response
<
String
>
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
"Filename"
)
String
Filename
)
{
public
Response
<
String
>
uploadFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
"Filename"
)
String
Filename
)
{
try
{
try
{
String
[]
fileNames
=
Filename
.
split
(
"/"
);;
String
[]
fileNames
=
Filename
.
split
(
"/"
);;
String
bucketName
=
fileNames
[
0
];
String
bucketName
=
fileNames
[
0
];
minioTools
.
uplodFile
(
bucketName
,
fileNames
[
1
],
file
.
getInputStream
());
String
name
=
fileNames
[
1
];
return
Response
.
ok
(
minioTools
.
getFile
(
bucketName
,
fileNames
[
1
]));
minioTools
.
uplodFile
(
bucketName
,
name
,
file
.
getInputStream
());
return
Response
.
ok
(
pcHostUrl
+
"/api/v1/buckets/"
+
bucketName
+
"/objects/download/?preview=true&prefix="
+
name
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
return
Response
.
fail
(
"Could not upload the file: "
+
Filename
);
return
Response
.
fail
(
"Could not upload the file: "
+
Filename
);
}
}
...
...
cloud-aliyun-service/src/main/java/com/yizhi/aliyun/application/controller/PolicyController.java
View file @
f7e15fdf
...
@@ -38,6 +38,9 @@ public class PolicyController {
...
@@ -38,6 +38,9 @@ public class PolicyController {
@Value
(
"${ACTIVE}"
)
@Value
(
"${ACTIVE}"
)
public
String
active
;
public
String
active
;
@Value
(
"${pc.host.url}"
)
String
pcHostUrl
;
@Autowired
@Autowired
PropertiesUtil
propertiesUtil
;
PropertiesUtil
propertiesUtil
;
...
@@ -81,32 +84,32 @@ public class PolicyController {
...
@@ -81,32 +84,32 @@ public class PolicyController {
}
}
String
host
=
"https://"
+
bucket
+
"."
+
endpoint
;
String
host
=
"https://"
+
bucket
+
"."
+
endpoint
;
//String host = pcHostUrl+"/api/v1/buckets/"+dir+"/objects/download/?preview=true&prefix=";
OSSClient
client
=
new
OSSClient
(
endpoint
,
accessId
,
accessKey
);
// OSSClient client = new OSSClient(endpoint, accessId, accessKey);
try
{
try
{
//
long expireTime = 60 * 24;
long
expireTime
=
60
*
24
;
//
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
long
expireEndTime
=
System
.
currentTimeMillis
()
+
expireTime
*
1000
;
//
Date expiration = new Date(expireEndTime);
Date
expiration
=
new
Date
(
expireEndTime
);
//
PolicyConditions policyConds = new PolicyConditions();
PolicyConditions
policyConds
=
new
PolicyConditions
();
//
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 10485760000L);
policyConds
.
addConditionItem
(
PolicyConditions
.
COND_CONTENT_LENGTH_RANGE
,
0
,
10485760000L
);
//
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
policyConds
.
addConditionItem
(
MatchMode
.
StartWith
,
PolicyConditions
.
COND_KEY
,
dir
);
//
String postPolicy = client.generatePostPolicy(expiration, policyConds);
String
postPolicy
=
client
.
generatePostPolicy
(
expiration
,
policyConds
);
//
byte[] binaryData = postPolicy.getBytes("utf-8");
byte
[]
binaryData
=
postPolicy
.
getBytes
(
"utf-8"
);
//
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
String
encodedPolicy
=
BinaryUtil
.
toBase64String
(
binaryData
);
//
String postSignature = client.calculatePostSignature(postPolicy);
String
postSignature
=
client
.
calculatePostSignature
(
postPolicy
);
Map
<
String
,
String
>
respMap
=
new
LinkedHashMap
<
String
,
String
>();
Map
<
String
,
String
>
respMap
=
new
LinkedHashMap
<
String
,
String
>();
respMap
.
put
(
"accessid"
,
accessId
);
respMap
.
put
(
"accessid"
,
accessId
);
respMap
.
put
(
"policy"
,
"encodedPolicy"
);
respMap
.
put
(
"policy"
,
encodedPolicy
);
respMap
.
put
(
"signature"
,
"postSignature"
);
respMap
.
put
(
"signature"
,
postSignature
);
respMap
.
put
(
"expire"
,
"formatISO8601Date(expiration)"
);
//respMap.put("expire", formatISO8601Date(expiration)
);
respMap
.
put
(
"dir"
,
dir
);
respMap
.
put
(
"dir"
,
dir
);
respMap
.
put
(
"host"
,
host
);
respMap
.
put
(
"host"
,
host
);
respMap
.
put
(
"expire"
,
"String.valueOf(expireEndTime / 1000)"
);
respMap
.
put
(
"expire"
,
String
.
valueOf
(
expireEndTime
/
1000
)
);
respMap
.
put
(
"active"
,
active
);
respMap
.
put
(
"active"
,
active
);
JSONObject
ja1
=
JSONObject
.
fromObject
(
respMap
);
JSONObject
ja1
=
JSONObject
.
fromObject
(
respMap
);
System
.
out
.
println
(
ja1
.
toString
());
System
.
out
.
println
(
ja1
.
toString
());
...
@@ -115,7 +118,7 @@ public class PolicyController {
...
@@ -115,7 +118,7 @@ public class PolicyController {
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
return
Response
.
fail
(
e
.
getMessage
());
return
Response
.
fail
(
e
.
getMessage
());
}
finally
{
}
finally
{
//
client.shutdown();
client
.
shutdown
();
}
}
}
}
...
...
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