Skip to content

Commit e781718

Browse files
author
阳光开朗大男孩
committed
增加图片上传安全验证
1 parent b2d637c commit e781718

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

aurora-springboot/src/main/java/com/aurora/strategy/impl/LocalUploadStrategyImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public class LocalUploadStrategyImpl extends AbstractUploadStrategyImpl {
1717
@Value("${upload.local.baseUrl}")
1818
private String baseUrl;
1919

20+
@Value("${upload.local.username}")
21+
private String username;
22+
23+
@Value("${upload.local.password}")
24+
private String password;
25+
2026
@Autowired
2127
private LocalProperties localProperties;
2228
private String imagePath;
@@ -33,9 +39,17 @@ public Boolean exists(String filePath) {
3339
// 检查文件是否存在
3440
return new File(imagePath + filePath).exists();
3541
}
42+
private boolean validateCredentials() {
43+
// 在这里实现账号密码验证逻辑,例如:
44+
return "admin".equals(username) && "secretpassword".equals(password);
45+
}
3646

3747
@Override
3848
public void upload(String path, String fileName, InputStream inputStream) throws IOException {
49+
// 验证账号密码
50+
if (!validateCredentials()) {
51+
throw new RuntimeException("无效的凭据");
52+
}
3953
// 重命名文件,添加自定义前缀
4054
// String customFileName = "aurora_" + fileName;
4155
String customFileName = fileName;

aurora-springboot/src/main/resources/application-prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ upload:
104104
secretKey: 密码
105105
bucketName: 桶的名称
106106
local:
107+
username: admin
108+
password: secretpassword
107109
imagePath: 'C:/code/images/'
108110
baseUrl: http://localhost:8080/
109111
# baseUrl: https://local.gysy.ltd/

0 commit comments

Comments
 (0)