good morning!!!!

Skip to content
Snippets Groups Projects
Commit 2072f031 authored by or-else's avatar or-else
Browse files

fix web attachment downloads by adding Content-Disposition header

parent dda74cdd
Branches
Tags v0.22.6
No related merge requests found
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"io" "io"
"math/rand" "math/rand"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
...@@ -133,7 +134,9 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) { ...@@ -133,7 +134,9 @@ func largeFileServe(wrt http.ResponseWriter, req *http.Request) {
defer rsc.Close() defer rsc.Close()
wrt.Header().Set("Content-Type", fd.MimeType) wrt.Header().Set("Content-Type", fd.MimeType)
if isAttachment, _ := strconv.ParseBool(req.URL.Query().Get("asatt")); isAttachment {
wrt.Header().Set("Content-Disposition", "attachment") wrt.Header().Set("Content-Disposition", "attachment")
}
http.ServeContent(wrt, req, "", fd.UpdatedAt, rsc) http.ServeContent(wrt, req, "", fd.UpdatedAt, rsc)
logs.Info.Println("media serve: OK, uid=", uid) logs.Info.Println("media serve: OK, uid=", uid)
...@@ -265,7 +268,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) { ...@@ -265,7 +268,7 @@ func largeFileReceive(wrt http.ResponseWriter, req *http.Request) {
} }
mimeType := http.DetectContentType(buff) mimeType := http.DetectContentType(buff)
// If DetectContentType failed, use user-provided content type. // If DetectContentType fails, use client-provided content type.
if mimeType == "application/octet-stream" { if mimeType == "application/octet-stream" {
if contentType := header.Header.Get("Content-Type"); contentType != "" { if contentType := header.Header.Get("Content-Type"); contentType != "" {
mimeType = contentType mimeType = contentType
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io" "io"
"mime" "mime"
"net/http" "net/http"
"strconv"
"sync/atomic" "sync/atomic"
"time" "time"
...@@ -172,10 +173,15 @@ func (ah *awshandler) Headers(req *http.Request, serve bool) (http.Header, int, ...@@ -172,10 +173,15 @@ func (ah *awshandler) Headers(req *http.Request, serve bool) (http.Header, int,
var awsReq *request.Request var awsReq *request.Request
if req.Method == http.MethodGet { if req.Method == http.MethodGet {
var contentDisposition *string
if isAttachment, _ := strconv.ParseBool(req.URL.Query().Get("asatt")); isAttachment {
contentDisposition = aws.String("attachment")
}
awsReq, _ = ah.svc.GetObjectRequest(&s3.GetObjectInput{ awsReq, _ = ah.svc.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String(ah.conf.BucketName), Bucket: aws.String(ah.conf.BucketName),
Key: aws.String(fid.String32()), Key: aws.String(fid.String32()),
ResponseContentType: aws.String(fd.MimeType), ResponseContentType: aws.String(fd.MimeType),
ResponseContentDisposition: contentDisposition,
}) })
} else if req.Method == http.MethodHead { } else if req.Method == http.MethodHead {
awsReq, _ = ah.svc.HeadObjectRequest(&s3.HeadObjectInput{ awsReq, _ = ah.svc.HeadObjectRequest(&s3.HeadObjectInput{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment