public JsonResult UploadMaterial(MediaUploadTypes type) { var context = this.OS.WorkContext.HttpContext.Request.Files ?? null; if (context == null || context.Count.Equals(0)) { return(Json(new { result = "fail" }, JsonRequestBehavior.AllowGet)); } using (var stream = new BinaryReader(context[0].InputStream)) { var buffers = stream.ReadBytes(context[0].ContentLength); switch (type) { case MediaUploadTypes.AuthMaterial: { ////TODO 需要返回 url var result = this.WeChat.UploadMaterial(context[0].FileName, buffers); return(Json(result, JsonRequestBehavior.AllowGet)); } default: { var result = this.WeChat.UploadMaterialToCDN(buffers); return(Json(result, JsonRequestBehavior.AllowGet)); } } } }
public static string GenerateWxUploaMediaUrl(string token, MediaUploadTypes type) { switch (type) { case MediaUploadTypes.AuthMaterial: return string.Format("https://api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type=image", token); default: // Image return string.Format("https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token={0}", token); } }
public ImageUploadUIElement( string name, string text, MediaUploadTypes type, string value = null, bool required = false, string imageUrl = null, string message = null) : base(name, text, value, required, message) { this.MediaUploadTypes = type; this.Value = value; this.ImageUrl = imageUrl; }