|
@@ -6,6 +6,7 @@ import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"io"
|
|
"io"
|
|
|
|
|
+ "net/url"
|
|
|
"os/user"
|
|
"os/user"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
"sort"
|
|
"sort"
|
|
@@ -366,7 +367,10 @@ func DownloadAiFile(c *fiber.Ctx) error {
|
|
|
fileName = fileName[9:]
|
|
fileName = fileName[9:]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- c.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
|
|
|
|
|
|
|
+ // 文件名可能含中文/非 ASCII,必须做 RFC 5987 编码后再写入响应头,
|
|
|
|
|
+ // 否则 Content-Disposition 含非法非 ASCII 字节,nginx 会判定 upstream 响应头非法而返回 502。
|
|
|
|
|
+ encoded := url.PathEscape(fileName)
|
|
|
|
|
+ c.Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s; filename*=UTF-8''%s", encoded, encoded))
|
|
|
c.Set("Content-Type", stat.ContentType)
|
|
c.Set("Content-Type", stat.ContentType)
|
|
|
return c.Send(data)
|
|
return c.Send(data)
|
|
|
}
|
|
}
|