Skip to content

Commit a795067

Browse files
committed
fix: fix the illegal character code error when list objects
1 parent c90bc89 commit a795067

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

dth/client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"io"
2626
"log"
27+
"net/url"
2728
"strings"
2829
"sync"
2930
"time"
@@ -173,6 +174,7 @@ func (c *S3Client) listObjectFn(ctx context.Context, continuationToken, prefix,
173174
Prefix: prefix,
174175
MaxKeys: maxKeys,
175176
Delimiter: delimiter,
177+
EncodingType: "url",
176178
}
177179

178180
if *continuationToken != "" {
@@ -280,8 +282,12 @@ func (c *S3Client) ListObjects(ctx context.Context, continuationToken, prefix *s
280282
if obj.StorageClass == "GLACIER" || obj.StorageClass == "DEEP_ARCHIVE" {
281283
continue
282284
}
285+
escapedPrefix, err := url.QueryUnescape(*obj.Key)
286+
if err != nil {
287+
escapedPrefix = *obj.Key
288+
}
283289
result = append(result, &Object{
284-
Key: *obj.Key,
290+
Key: escapedPrefix,
285291
Size: obj.Size,
286292
})
287293
}
@@ -602,3 +608,7 @@ func (c *S3Client) AbortMultipartUpload(ctx context.Context, key, uploadID *stri
602608

603609
return nil
604610
}
611+
612+
func urlEncodePath(path string) string {
613+
return (&url.URL{Path: path}).EscapedPath()
614+
}

0 commit comments

Comments
 (0)