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

add stream_upload_source #786

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

oah8
Copy link
Contributor

@oah8 oah8 commented Jul 23, 2024

No description provided.

@oah8 oah8 force-pushed the feat_stream_upload_tempmaterials branch 2 times, most recently from 0ba62d8 to b47cbba Compare July 23, 2024 15:39
util/http.go Outdated
@@ -8,13 +8,13 @@ import (
"encoding/pem"
"encoding/xml"
"fmt"
"golang.org/x/crypto/pkcs12"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一行 import 放到17行,path包放在os包下面

Copy link
Collaborator

@houseme houseme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

按照提示修改一下

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法参数含义从本地文件变成远程资源,是不是另起一个方法会好一些?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改为UploadRemoteTempFile

var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return nil, err
}
filename, byteData, err := util.GetFileSourceByURL(url)
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个util里的PostFileFromReader函数好像复用不了 😭

@oah8
Copy link
Contributor Author

oah8 commented Jul 24, 2024

按照提示修改一下

@oah8 oah8 force-pushed the feat_stream_upload_tempmaterials branch from b47cbba to 26a6d7d Compare July 24, 2024 13:05
@oah8
Copy link
Contributor Author

oah8 commented Aug 5, 2024

按照提示修改一下

你好,要是被合并需要满足啥条件

// @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) {
Copy link
Collaborator

@houseme houseme Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个方法名字不要改动了,之内改掉会影响之前版本的升级

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好,已改回

@oah8 oah8 force-pushed the feat_stream_upload_tempmaterials branch from 26a6d7d to e55faeb Compare August 5, 2024 14:11
@houseme houseme requested review from PublicPwd and silenceper and removed request for PublicPwd August 6, 2024 07:43
@@ -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) {
Copy link
Contributor

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)

@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为了兼容已发布的版本,这块和其它类似地方是不是应该改回 UploadTempFile(filename string, mediaType string) @houseme

URL 相关参数就新起一个方法来实现 @oah8

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是有新增参数,可以创建新的方法

Copy link
Contributor Author

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)
Copy link
Contributor

@PublicPwd PublicPwd Aug 7, 2024

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() 实现

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好,我改下

@oah8 oah8 force-pushed the feat_stream_upload_tempmaterials branch from e55faeb to ed149ad Compare August 10, 2024 16:48
@oah8 oah8 force-pushed the feat_stream_upload_tempmaterials branch from ed149ad to a8e6bce Compare August 10, 2024 16:53
@oah8
Copy link
Contributor Author

oah8 commented Aug 10, 2024

已更改 😭

@silenceper silenceper merged commit c177013 into silenceper:v2 Aug 22, 2024
13 checks passed
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

Successfully merging this pull request may close these issues.

5 participants