diff --git a/src/main/java/run/halo/s3os/S3LinkServiceImpl.java b/src/main/java/run/halo/s3os/S3LinkServiceImpl.java index 2e8533b..1fc6e33 100644 --- a/src/main/java/run/halo/s3os/S3LinkServiceImpl.java +++ b/src/main/java/run/halo/s3os/S3LinkServiceImpl.java @@ -184,7 +184,7 @@ public Mono addAttachmentRecord(String policyName, .map(headObjectResponse -> { var objectDetail = new S3OsAttachmentHandler.ObjectDetail( new S3OsAttachmentHandler.UploadState(properties, - FileNameUtils.extractFileNameFromS3Key(objectKey)), + FileNameUtils.extractFileNameFromS3Key(objectKey), false), headObjectResponse); return handler.buildAttachment(properties, objectDetail); }) diff --git a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java index 1e5b955..17e74f8 100644 --- a/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java +++ b/src/main/java/run/halo/s3os/S3OsAttachmentHandler.java @@ -304,7 +304,7 @@ ByteBuffer deepCopy(ByteBuffer src) { Mono upload(UploadContext uploadContext, S3OsProperties properties) { return Mono.using(() -> buildS3Client(properties), client -> { - var uploadState = new UploadState(properties, uploadContext.file().filename()); + var uploadState = new UploadState(properties, uploadContext.file().filename(), true); var content = uploadContext.file().content(); @@ -492,12 +492,14 @@ static class UploadState { String objectKey; boolean needRemoveMapKey = false; - public UploadState(S3OsProperties properties, String fileName) { + public UploadState(S3OsProperties properties, String fileName, boolean needRandomJudge) { this.properties = properties; this.originalFileName = fileName; - fileName = FileNameUtils.getRandomFilename(fileName, + if (needRandomJudge) { + fileName = FileNameUtils.getRandomFilename(fileName, properties.getRandomStringLength(), properties.getRandomFilenameMode()); + } this.fileName = fileName; this.objectKey = properties.getObjectName(fileName);