WeiXinMPSDK icon indicating copy to clipboard operation
WeiXinMPSDK copied to clipboard

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

Open carto1111 opened this issue 1 year ago • 3 comments

问题描述

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

  • [x] 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
  • [x] .net 7.0
开发环境
  • [ ] Visual Studio 2019
  • [x] Visual Studio 2022
  • [ ] Visual Studio Code
  • [ ] 其他:
缓存环境
  • [x] 服务器内存缓存(默认)
  • [ ] Redis 版本:
  • [ ] Memcached 版本:
  • [ ] 其他:
系统环境
  • [x] Windows,版本:
  • [ ] Linux,版本:
  • [ ] Mac,版本:
  • [ ] 其他:

carto1111 avatar Feb 28 '24 09:02 carto1111

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

JeffreySu avatar Feb 28 '24 12:02 JeffreySu

大师,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<UploadTemporaryResultJson>(CommonDI.CommonSP, url, null, fileDictionary, null, null, null, false, timeOut: timeOut); }, accessTokenOrAppKey);

    }

carto1111 avatar Feb 28 '24 14:02 carto1111

@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

JaneConan avatar Jun 05 '24 06:06 JaneConan