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

企业微信上传文件的接口是错的,引起媒体文件为空 #2992

Open
5 of 22 tasks
carto1111 opened this issue Feb 28, 2024 · 3 comments
Open
5 of 22 tasks

Comments

@carto1111
Copy link

carto1111 commented Feb 28, 2024

问题描述

你好,上传文件的接口是错的,media直接传的是文件路径,没有filename、filelength、content-type等

  • Senparc.Weixin.Work 版本:
模块对应的 .net 版本
  • .net 3.5
  • .net 4.0
  • .net 4.5+
  • .net standard 2.0 / 2.1
  • .net core 1.x
  • .net core 2.x
  • .net core 3.x
  • .net 5.x / 6.x
  • .net 7.0
开发环境
  • Visual Studio 2019
  • Visual Studio 2022
  • Visual Studio Code
  • 其他:
缓存环境
  • 服务器内存缓存(默认)
  • Redis 版本:
  • Memcached 版本:
  • 其他:
系统环境
  • Windows,版本:
  • Linux,版本:
  • Mac,版本:
  • 其他:
@JeffreySu
Copy link
Owner

@carto1111  方便把你能重现问题的代码展示一下吗?

@carto1111
Copy link
Author

大师,SDK源码里
src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/Media/MediaApi.cs
这里面的上传方法,教程里面都是直接调用传路径进来,看来是少了media文件标识,微信返回媒体文件为空。
///


/// 上传临时媒体文件【QY移植修改】
///

/// 调用接口凭证(AccessToken)或AppKey(根据AccessTokenContainer.BuildingKey(corpId, corpSecret)方法获得)
/// 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
/// form-data中媒体文件标识,有filename、filelength、content-type等信息
/// 代理请求超时时间(毫秒)
///
public static UploadTemporaryResultJson Upload(string accessTokenOrAppKey, UploadMediaFileType type, string media, int timeOut = Config.TIME_OUT)
{
return ApiHandlerWapper.TryCommonApi(accessToken =>
{
var url = string.Format(Config.ApiWorkHost + "/cgi-bin/media/upload?access_token={0}&type={1}", accessToken.AsUrlData(), type.ToString());
var fileDictionary = new Dictionary<string, string>();
fileDictionary["media"] = media;
return CO2NET.HttpUtility.Post.PostFileGetJson(CommonDI.CommonSP, url, null, fileDictionary, null, null, null, false, timeOut: timeOut);
}, accessTokenOrAppKey);

    }

@JaneConan
Copy link
Contributor

@carto1111 您好,您指的接口有错误是,https://developer.work.weixin.qq.com/document/path/95178,这个接口么
确实,我们现在的路径是,/cgi-bin/media/upload?access_token={0}&type={1}

而企业微信里是,/cgi-bin/media/upload_attachment?access_token=ACCESS_TOKEN&media_type=TYPE&attachment_type=1

还有POST的请求包中,form-data中媒体文件标识,应包含有 filename、filelength、content-type等信息

您是说如下图的意思么
image

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

No branches or pull requests

3 participants