Fix non-ASCII characters in filename unsupported
fix #62 Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -171,11 +172,16 @@ func (s EvidenceService) GenerateFileURL(
|
|||||||
|
|
||||||
presignClient := s3.NewPresignClient(s.svc.s3)
|
presignClient := s3.NewPresignClient(s.svc.s3)
|
||||||
|
|
||||||
|
// Use RFC 6266/5987 encoding for filename with UTF-8 support
|
||||||
|
encodedFilename := url.QueryEscape(evidence.Filename)
|
||||||
|
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
||||||
|
encodedFilename, encodedFilename)
|
||||||
|
|
||||||
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
||||||
Bucket: aws.String(s.svc.bucket),
|
Bucket: aws.String(s.svc.bucket),
|
||||||
Key: aws.String(evidence.ObjectKey),
|
Key: aws.String(evidence.ObjectKey),
|
||||||
ResponseContentType: aws.String(evidence.MimeType),
|
ResponseContentType: aws.String(evidence.MimeType),
|
||||||
ResponseContentDisposition: aws.String(fmt.Sprintf("attachment; filename=\"%s\"", evidence.Filename)),
|
ResponseContentDisposition: aws.String(contentDisposition),
|
||||||
}, func(opts *s3.PresignOptions) {
|
}, func(opts *s3.PresignOptions) {
|
||||||
opts.Expires = expiresIn
|
opts.Expires = expiresIn
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user