Fix file download Content-Disposition header format
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix file download Content-Disposition header format
|
||||||
|
|
||||||
## [0.69.0] - 2025-10-13
|
## [0.69.0] - 2025-10-13
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -93,13 +93,16 @@ func (s FileService) UploadAndSaveFile(
|
|||||||
return nil, fmt.Errorf("cannot validate file: %w", err)
|
return nil, fmt.Errorf("cannot validate file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.svc.s3.PutObject(ctx, &s3.PutObjectInput{
|
_, err = s.svc.s3.PutObject(
|
||||||
|
ctx,
|
||||||
|
&s3.PutObjectInput{
|
||||||
Bucket: &s.svc.bucket,
|
Bucket: &s.svc.bucket,
|
||||||
Key: aws.String(objectKey.String()),
|
Key: aws.String(objectKey.String()),
|
||||||
Body: req.Content,
|
Body: req.Content,
|
||||||
Metadata: s3Metadata,
|
Metadata: s3Metadata,
|
||||||
ContentType: aws.String(mimeType),
|
ContentType: aws.String(mimeType),
|
||||||
})
|
},
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot upload file to S3: %w", err)
|
return nil, fmt.Errorf("cannot upload file to S3: %w", err)
|
||||||
}
|
}
|
||||||
@@ -120,7 +123,6 @@ func (s FileService) UploadAndSaveFile(
|
|||||||
err = s.svc.pg.WithTx(
|
err = s.svc.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(conn pg.Conn) error {
|
func(conn pg.Conn) error {
|
||||||
|
|
||||||
file = &coredata.File{
|
file = &coredata.File{
|
||||||
ID: fileID,
|
ID: fileID,
|
||||||
BucketName: s.svc.bucket,
|
BucketName: s.svc.bucket,
|
||||||
@@ -161,18 +163,20 @@ func (s FileService) GenerateFileTempURL(
|
|||||||
|
|
||||||
// Use RFC 6266/5987 encoding for filename with UTF-8 support
|
// Use RFC 6266/5987 encoding for filename with UTF-8 support
|
||||||
encodedFilename := url.QueryEscape(file.FileName)
|
encodedFilename := url.QueryEscape(file.FileName)
|
||||||
contentDisposition := fmt.Sprintf("attachment; filename=\"%s\"; filename*=UTF-8''%s",
|
contentDisposition := fmt.Sprintf("attachment; filename=%q; filename*=UTF-8''%s",
|
||||||
encodedFilename, encodedFilename)
|
encodedFilename, encodedFilename)
|
||||||
|
|
||||||
presignedReq, err := presignClient.PresignGetObject(ctx, &s3.GetObjectInput{
|
presignedReq, err := presignClient.PresignGetObject(
|
||||||
Bucket: aws.String(s.svc.bucket),
|
ctx,
|
||||||
Key: aws.String(file.FileKey),
|
&s3.GetObjectInput{
|
||||||
|
Bucket: &s.svc.bucket,
|
||||||
|
Key: &file.FileKey,
|
||||||
ResponseCacheControl: aws.String("max-age=3600, public"),
|
ResponseCacheControl: aws.String("max-age=3600, public"),
|
||||||
ResponseContentType: aws.String(file.MimeType),
|
ResponseContentType: &file.MimeType,
|
||||||
ResponseContentDisposition: aws.String(fmt.Sprintf("attachment; filename=\"%s\"", contentDisposition)),
|
ResponseContentDisposition: &contentDisposition,
|
||||||
}, func(opts *s3.PresignOptions) {
|
},
|
||||||
opts.Expires = expiresIn
|
func(opts *s3.PresignOptions) { opts.Expires = expiresIn },
|
||||||
})
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
|
return "", fmt.Errorf("cannot presign GetObject request: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user