It is implementing a file download API
The problem is that the Korean file name is broken
text: "AWS자산.svg"
my code ↓
import ("github.com/gin-gonic/gin""net/url") func FileDownload(c *gin.Context) { result, infos := fileDownload(c) if result.Code == 200 { c.Writer.Header().Set("Content-Type", infos.FileType) /* infos.FileOgName = AWS자산.svg */ c.FileAttachment(infos.FilePath, infos.FileOgName) // 1 image c.FileAttachment(infos.FilePath, url.QueryEscape(infos.FileOgName)) // 2 image } else { c.JSON(result.Code, result) }}
// 3 imagefunc (c \*Context) FileAttachment(filepath, filename string) { c.Writer.Header().Set("content-disposition", fmt.Sprintf(attachment; filename\*="UTF-8''%s", filename)) http.ServeFile(c.Writer, c.Request, filepath)}
I conducted three tests
- I sent you a pure file name.test 1 image
- url encodingtest 2 image
- Apply by referring to the Internet (filename*="UTF-8''%s")test 3 image
The problem has not been solved.
I need help from good developers
----------2022-12-09 update-----------
[go gin 1.8.1]The module update has been completed, but the problem remains.
// FileAttachment writes the specified file into the body stream in an efficient way// On the client side, the file will typically be downloaded with the given filenamefunc (c *Context) FileAttachment(filepath, filename string) { if isASCII(filename) { c.Writer.Header().Set("Content-Disposition", `attachment; filename="`+filename+`"`) } else { c.Writer.Header().Set("Content-Disposition", `attachment; filename*=UTF-8''`+url.QueryEscape(filename)) } http.ServeFile(c.Writer, c.Request, filepath)}