.net core API 微信上传图片接口的实现 media data missing hint

API:https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN

代码实现

		/// <summary>
		/// 上传图片素材
		/// </summary>
		/// <param name="access_token">公众号token</param>
		/// <param name="buffer">文件的数据流</param>
		/// <param name="FileName">文件名</param>
		/// <returns></returns>
		public async Task<Entity.RetModels.Retmsg> Senduploadimg(string access_token, Stream buffer,string FileName)
		{
		// 接口
			string APIStr = ConfigHelp.ConfigHelper.GetSectionValue("WechatAPI:Get_API_weixin:Senduploadimg");
			// 拼接API
			string APIUrl = string.Format("{0}?access_token={1}", APIStr, access_token);
			var formdata = new MultipartFormDataContent();
			formdata.Headers.ContentType = new MediaTypeHeaderValue("multipart/form-data");
			// formdata.Add(new StringContent(access_token), "access_token");
			formdata.Add(new StreamContent(buffer), "buffer", "\"" + FileName +"\"");

			var response = await _Client.PostAsync(APIUrl, formdata);
			string RetJson = await response.Content.ReadAsStringAsync();//获取返回的Json字符串
			// 
			}
	formdata.Add(new StreamContent(buffer), "buffer", "\"" + FileName +"\"");
	大佬能解释下为啥要加上\“,卡了我一天

在这里插入图片描述
得到了想要的结果
在这里插入图片描述

参考资料
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值