-
-
Notifications
You must be signed in to change notification settings - Fork 891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Message GetFile() #31
Comments
请看示例 |
|
|
filename似乎是拿不到的 |
OK, no way to derive a file name for that For the unnamed cases, like pictures, or voices, I found from Thanks |
|
Thanks a lot! |
有些类型的文件是可以拿到文件名的
|
Love it bro. thx a lot! |
I'll look into whether we can wrap up everything inside openwechat, instead of pushing all above to the client side... |
collecting how to use //判断文件协议content-type,0表示xml,1表示
//alter: ,by: ,time: ,#第几次修改
func DecideFile(body []byte) int {
if http.DetectContentType(body) == "text/xml; charset=utf-8" {
return 0
} else if http.DetectContentType(body) == "text/plain; charset=utf-8" {
return 1
}
return 3
}
func IsPDFFile(data []byte) (string, bool) {
contentType := http.DetectContentType(data)
if strings.Index(contentType, "application/pdf") != -1 {
return contentType, true
}
return contentType, false
} and with func (r *ResponseDetails) ConvertToResponseDetailsView() views.ResponseDetailsView {
needsEncoding := false
// Check headers for gzip
contentEncodingValues := r.Headers["Content-Encoding"]
if len(contentEncodingValues) > 0 {
needsEncoding = true
} else {
mimeType := http.DetectContentType([]byte(r.Body))
needsEncoding = true
for _, v := range supportedMimeTypes {
if strings.Contains(mimeType, v) {
needsEncoding = false
break
}
}
}
// If contains gzip, base64 encode
body := r.Body
if needsEncoding {
body = base64.StdEncoding.EncodeToString([]byte(r.Body))
}
return views.ResponseDetailsView{Status: r.Status, Body: body, Headers: r.Headers, EncodedBody: needsEncoding}
} and just in case need to further parse the ContentType, e.g., |
|
Hi @eatmoreapple,
Do you have sample code how to use the
func (*Message) GetFile
and save it to disk please?I assume it'll be another FAQ, and I don't know how you derive a file name for that
GetFile
. Thx!The text was updated successfully, but these errors were encountered: