Skip to content

Commit

Permalink
Fix url space error (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
longjuan committed Jun 1, 2023
1 parent b3bdd02 commit 022ecea
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/run/halo/s3os/S3OsAttachmentHandler.java
Expand Up @@ -171,8 +171,8 @@ Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail)
var metadata = new Metadata();
metadata.setName(UUID.randomUUID().toString());
metadata.setAnnotations(new HashMap<>(
Map.of(OBJECT_KEY, objectDetail.uploadState.objectKey, Constant.EXTERNAL_LINK_ANNO_KEY,
UriUtils.encodePath(externalLink, StandardCharsets.UTF_8))));
Map.of(OBJECT_KEY, objectDetail.uploadState.objectKey,
Constant.EXTERNAL_LINK_ANNO_KEY, externalLink)));

var objectMetadata = objectDetail.objectMetadata();
var spec = new AttachmentSpec();
Expand All @@ -189,17 +189,19 @@ Attachment buildAttachment(S3OsProperties properties, ObjectDetail objectDetail)
}

private String getObjectURL(S3OsProperties properties, String objectKey) {
String objectURL;
if (StringUtils.isBlank(properties.getDomain())) {
String host;
if (properties.getEnablePathStyleAccess()) {
host = properties.getEndpoint() + "/" + properties.getBucket();
} else {
host = properties.getBucket() + "." + properties.getEndpoint();
}
return properties.getProtocol() + "://" + host + "/" + objectKey;
objectURL = properties.getProtocol() + "://" + host + "/" + objectKey;
} else {
return properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;
objectURL = properties.getProtocol() + "://" + properties.getDomain() + "/" + objectKey;
}
return UriUtils.encodePath(objectURL, StandardCharsets.UTF_8);
}

S3Client buildS3Client(S3OsProperties properties) {
Expand Down

0 comments on commit 022ecea

Please sign in to comment.