-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add stream_upload_source #786
add stream_upload_source #786
Conversation
0ba62d8
to
b47cbba
Compare
util/http.go
Outdated
@@ -8,13 +8,13 @@ import ( | |||
"encoding/pem" | |||
"encoding/xml" | |||
"fmt" | |||
"golang.org/x/crypto/pkcs12" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这一行 import 放到17行,path包放在os包下面
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照提示修改一下
work/material/media.go
Outdated
@@ -59,16 +58,21 @@ func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) { | |||
// UploadTempFile 上传临时素材 | |||
// @see https://developer.work.weixin.qq.com/document/path/90253 | |||
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) | |||
func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempFileResponse, error) { | |||
// 临时素材一般都是存储在oss上的,可以直接传递url | |||
func (r *Client) UploadTempFile(url string, mediaType string) (*UploadTempFileResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法参数含义从本地文件变成远程资源,是不是另起一个方法会好一些?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改为UploadRemoteTempFile
work/material/media.go
Outdated
var ( | ||
accessToken string | ||
err error | ||
) | ||
if accessToken, err = r.GetAccessToken(); err != nil { | ||
return nil, err | ||
} | ||
filename, byteData, err := util.GetFileSourceByURL(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块是不是可以优化下,比如:
res, _ := http.Get()
defer res.body.Close()
somethingElse := res.Header.Get()
util.PostFileFromReader(_, _, _, res.body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个util里的PostFileFromReader函数好像复用不了 😭
好 |
b47cbba
to
26a6d7d
Compare
你好,要是被合并需要满足啥条件 |
work/material/media.go
Outdated
// @see https://developer.work.weixin.qq.com/document/path/90253 | ||
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) | ||
func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempFileResponse, error) { | ||
// 临时素材一般都是存储在oss上的,可以直接传递url | ||
func (r *Client) UploadRemoteTempFile(url string, mediaType string) (*UploadTempFileResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个方法名字不要改动了,之内改掉会影响之前版本的升级
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好,已改回
26a6d7d
to
e55faeb
Compare
officialaccount/material/material.go
Outdated
@@ -163,7 +164,7 @@ type resAddMaterial struct { | |||
} | |||
|
|||
// AddMaterialFromReader 上传永久性素材(处理视频需要单独上传),从 io.Reader 中读取 | |||
func (material *Material) AddMaterialFromReader(mediaType MediaType, filename string, reader io.Reader) (mediaID string, url string, err error) { | |||
func (material *Material) AddMaterialFromReader(mediaType MediaType, directory string, reader io.Reader) (mediaID string, url string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里 filename
直接改成 directory
似乎没有意义,如果为了素材库中展示的文件名,或许可以改成这样?
AddMaterialFromReader(mediaType MediaType, filePath, fileName string, reader io.Reader)
work/material/media.go
Outdated
@@ -59,16 +59,21 @@ func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) { | |||
// UploadTempFile 上传临时素材 | |||
// @see https://developer.work.weixin.qq.com/document/path/90253 | |||
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) | |||
func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempFileResponse, error) { | |||
// 临时素材一般都是存储在oss上的,可以直接传递url | |||
func (r *Client) UploadTempFile(url string, mediaType string) (*UploadTempFileResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是有新增参数,可以创建新的方法
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好
util/http.go
Outdated
err = fmt.Errorf("get resp error: %v", err) | ||
return | ||
} | ||
byteData, err = io.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的想法是 URL 可以在 SDK 外实现,比如:
const ossURL = ""
res, _ := http.Get(ossURL)
defer res.Body.Close()
officialaccount.Client.AddMaterialFromReader(_, _, res.Body)
或是 SDK 内部下载 URL 文件的话,就改成 io.Copy() 实现
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好,我改下
e55faeb
to
ed149ad
Compare
ed149ad
to
a8e6bce
Compare
已更改 😭 |
No description provided.