Skip to content

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

Open
@CMLiang

Description

@CMLiang

`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"`
但是这样意味着需要额外的调用,请问大家有遇到类似的问题吗?是怎么解决的?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions