Skip to content

Commit

Permalink
增加图片上传安全验证
Browse files Browse the repository at this point in the history
  • Loading branch information
阳光开朗大男孩 committed Feb 28, 2024
1 parent b2d637c commit e781718
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class LocalUploadStrategyImpl extends AbstractUploadStrategyImpl {
@Value("${upload.local.baseUrl}")
private String baseUrl;

@Value("${upload.local.username}")
private String username;

@Value("${upload.local.password}")
private String password;

@Autowired
private LocalProperties localProperties;
private String imagePath;
Expand All @@ -33,9 +39,17 @@ public Boolean exists(String filePath) {
// 检查文件是否存在
return new File(imagePath + filePath).exists();
}
private boolean validateCredentials() {
// 在这里实现账号密码验证逻辑,例如:
return "admin".equals(username) && "secretpassword".equals(password);
}

@Override
public void upload(String path, String fileName, InputStream inputStream) throws IOException {
// 验证账号密码
if (!validateCredentials()) {
throw new RuntimeException("无效的凭据");
}
// 重命名文件,添加自定义前缀
// String customFileName = "aurora_" + fileName;
String customFileName = fileName;
Expand Down
2 changes: 2 additions & 0 deletions aurora-springboot/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ upload:
secretKey: 密码
bucketName: 桶的名称
local:
username: admin
password: secretpassword
imagePath: 'C:/code/images/'
baseUrl: http://localhost:8080/
# baseUrl: https://local.gysy.ltd/
Expand Down

1 comment on commit e781718

@jiangwt1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增加图片上传安全验证

Please sign in to comment.