Skip to content

Commit c0fb2b1

Browse files
authored
fix: s3 link error when filename renaming enable (#91)
fixes #90 请测试 `上传时重命名文件方式` 选项为**非**保留原文件名时,是否能正常关联s3文件 ![image](https://github.com/halo-dev/plugin-s3/assets/28662535/22ab0467-60bd-4c4c-a486-38bc922b7f37) ```release-note 当上传时文件重命名功能开启时关联S3文件错误 ```
1 parent c79fee9 commit c0fb2b1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Diff for: src/main/java/run/halo/s3os/S3LinkServiceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public Mono<LinkResult.LinkResultItem> addAttachmentRecord(String policyName,
184184
.map(headObjectResponse -> {
185185
var objectDetail = new S3OsAttachmentHandler.ObjectDetail(
186186
new S3OsAttachmentHandler.UploadState(properties,
187-
FileNameUtils.extractFileNameFromS3Key(objectKey)),
187+
FileNameUtils.extractFileNameFromS3Key(objectKey), false),
188188
headObjectResponse);
189189
return handler.buildAttachment(properties, objectDetail);
190190
})

Diff for: src/main/java/run/halo/s3os/S3OsAttachmentHandler.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ ByteBuffer deepCopy(ByteBuffer src) {
304304
Mono<ObjectDetail> upload(UploadContext uploadContext, S3OsProperties properties) {
305305
return Mono.using(() -> buildS3Client(properties),
306306
client -> {
307-
var uploadState = new UploadState(properties, uploadContext.file().filename());
307+
var uploadState = new UploadState(properties, uploadContext.file().filename(), true);
308308

309309
var content = uploadContext.file().content();
310310

@@ -492,12 +492,14 @@ static class UploadState {
492492
String objectKey;
493493
boolean needRemoveMapKey = false;
494494

495-
public UploadState(S3OsProperties properties, String fileName) {
495+
public UploadState(S3OsProperties properties, String fileName, boolean needRandomJudge) {
496496
this.properties = properties;
497497
this.originalFileName = fileName;
498498

499-
fileName = FileNameUtils.getRandomFilename(fileName,
499+
if (needRandomJudge) {
500+
fileName = FileNameUtils.getRandomFilename(fileName,
500501
properties.getRandomStringLength(), properties.getRandomFilenameMode());
502+
}
501503

502504
this.fileName = fileName;
503505
this.objectKey = properties.getObjectName(fileName);

0 commit comments

Comments
 (0)