/// <summary>
        /// 添加文件内容到已有的Content
        /// 要求content-type为multipart/form-data
        /// </summary>
        /// <param name="stream">文件流</param>
        /// <param name="name">名称</param>
        /// <param name="fileName">文件名</param>
        /// <param name="contentType">文件Mime</param>
        /// <exception cref="NotSupportedException"></exception>
        public void AddMulitpartFile(Stream stream, string name, string fileName, string contentType)
        {
            this.EnsureNotGetOrHead();

            var httpContent = this.CastOrCreateMultipartContent();
            var fileContent = new MulitpartFileContent(stream, name, fileName, contentType);

            httpContent.Add(fileContent);
            this.Content = httpContent;
        }
示例#2
0
        /// <summary>
        /// 执行请求前
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="parameter">特性关联的属性</param>
        async Task IApiParameterable.BeforeRequestAsync(ApiActionContext context, ApiParameterDescriptor parameter)
        {
            var method = context.RequestMessage.Method;

            if (method == HttpMethod.Get || method == HttpMethod.Head)
            {
                return;
            }

            var httpContent = context.RequestMessage.Content.CastMultipartContent();
            var fileContent = new MulitpartFileContent(this.GetStream(), parameter.Name, this.FileName, this.ContentType);

            httpContent.Add(fileContent);
            context.RequestMessage.Content = httpContent;
            await TaskExtend.CompletedTask;
        }
 /// <summary>
 /// 省略内容的文件请求内容
 /// </summary>
 /// <param name="fileContent">文件内容</param>
 public EllipsisContent(MulitpartFileContent fileContent)
     : base(ellipsisContent)
 {
     this.Headers.ContentDisposition = fileContent.Headers.ContentDisposition;
     this.Headers.ContentType        = fileContent.Headers.ContentType;
 }
示例#4
0
        /// <summary>
        /// 添加文件内容
        /// </summary>
        /// <param name="httpContent"></param>
        /// <param name="stream">文件流</param>
        /// <param name="name">名称</param>
        /// <param name="fileName">文件名</param>
        /// <param name="contentType">文件Mime</param>
        public static void AddFile(this MultipartContent httpContent, Stream stream, string name, string fileName, string contentType)
        {
            var fileContent = new MulitpartFileContent(stream, name, fileName, contentType);

            httpContent.Add(fileContent);
        }