コード例 #1
0
        /// <summary>
        /// form文件头(永久素材)
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="file"></param>
        /// <param name="type"></param>
        /// <param name="title"></param>
        /// <param name="introduction"></param>
        /// <returns></returns>
        public static MultipartFormDataContent BuildFromContentForever(string fileName, Stream file, EntMediaType type, string title, string introduction)
        {
            var Boundary = EntInterface.Boundary;
            MultipartFormDataContent form = new MultipartFormDataContent(Boundary);

            // 文件头
            form.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data;boundary=" + Boundary);
            // 视频特殊处理
            if (type == EntMediaType.video)
            {
                var video        = "{\"title\":\"" + title + "\", \"introduction\":\"" + introduction + "\"}";
                var videoContent = new StringContent(video);
                videoContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "\"description\"",
                };

                form.Add(videoContent);
            }

            var content = EntInterface.BuildStreamContent(fileName, file);

            form.Add(content);
            return(form);
        }
コード例 #2
0
        /// <summary>
        /// 新增临时素材
        /// </summary>
        /// <param name="file">文件流</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="type">媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)</param>
        /// <returns></returns>
        public static EntMediaResult AddMedia(Stream file, string fileName, EntMediaType type)
        {
            MultipartFormDataContent content = EntInterface.BuildFromContent(fileName, file);

            var url = string.Format(ADD_MEDIA_URL, EntInterface.AccessToken, type.ToString());

            return(WebApiHelper.PostHttpContent <EntMediaResult>(url, content));
        }