Skip to content
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

媒体/素材涉及Download的方法,在文件扩展名未知的情况下,如何传filepath参数? #264

Open
CMLiang opened this issue Aug 30, 2019 · 0 comments

Comments

@CMLiang
Copy link

CMLiang commented Aug 30, 2019

`func Download(clt *core.Client, mediaId, filepath string) (written int64, err error) {
file, err := os.Create(filepath)
if err != nil {
return
}
defer func() {
file.Close()
if err != nil {
os.Remove(filepath)
}
}()

return DownloadToWriter(clt, mediaId, file)

}如上例,根据mediaId下载多媒体到文件,但微信的消息中,除了语音消息,其他多媒体消息是未知文件扩展名的,目前认为,可以根据mediaId获取文件扩展名的方法就是调用微信获取素材的API,其返回的HTTP头中含有文件扩展名(如jpeg):HTTP/1.1 200 OK
Connection: close
Content-Type: image/jpeg
Content-disposition: attachment; filename="MEDIA_ID.jpg"
Date: Sun, 06 Jan 2013 10:20:18 GMT
Cache-Control: no-cache, must-revalidate
Content-Length: 339721
curl -G "https://api.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID"`
但是这样意味着需要额外的调用,请问大家有遇到类似的问题吗?是怎么解决的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant