Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1039

Content-Disposition utf8 encoding (golang)

$
0
0

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

  1. I sent you a pure file name.test 1 image
  2. url encodingtest 2 image
  3. 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)}

test 4 image


Viewing all articles
Browse latest Browse all 1039

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>