Skip to content

Commit

Permalink
fix: spaces in filename will be replaced with plus sign (#3841)
Browse files Browse the repository at this point in the history
Co-authored-by: XZB <i@1248.ink>
  • Loading branch information
XZB-1248 and XZB authored Mar 14, 2023
1 parent f3db23a commit c410800
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion drivers/s3/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func (d *S3) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]mo

func (d *S3) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
path := getKey(file.GetPath(), false)
disposition := fmt.Sprintf(`attachment;filename="%s"`, url.QueryEscape(stdpath.Base(path)))
filename := stdpath.Base(path)
disposition := fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename))
input := &s3.GetObjectInput{
Bucket: &d.Bucket,
Key: &path,
Expand Down
3 changes: 2 additions & 1 deletion server/common/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
defer func() {
_ = link.Data.Close()
}()
filename := file.GetName()
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, file.GetName(), url.QueryEscape(file.GetName())))
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, filename, url.PathEscape(filename)))
w.Header().Set("Content-Length", strconv.FormatInt(file.GetSize(), 10))
if link.Header != nil {
// TODO clean header with blacklist or whitelist
Expand Down

0 comments on commit c410800

Please sign in to comment.