Container for files to be uploaded with requests
Пример #1
0
        /// <summary>根据HttpBuilder构建RequestRequest请求
        /// </summary>
        public static IRestRequest BuildRequest(this HttpBuilder builder)
        {
            IRestRequest request = new RestRequest
            {
                Method   = ParseMethod(builder.Method),
                Resource = builder.Resource.IsNullOrWhiteSpace() ? "" : builder.Resource
            };

            foreach (var parameter in builder.Parameters)
            {
                var p = new RestSharp.Parameter()
                {
                    Name        = parameter.Name,
                    Value       = parameter.Value,
                    DataFormat  = parameter.DataFormat.ParseDataFormat(),
                    ContentType = parameter.ContentType,
                    Type        = parameter.Type.ParseParameterType()
                };
                request.AddParameter(p);
            }

            foreach (var file in builder.Files)
            {
                var f = new RestSharp.FileParameter()
                {
                    Name          = file.Name,
                    FileName      = file.FileName,
                    ContentLength = file.ContentLength,
                    ContentType   = file.ContentType,
                    Writer        = file.Writer
                };
                request.Files.Add(f);
            }

            return(request);
        }
Пример #2
0
		private IRestRequest AddFile (FileParameter file)
		{
			Files.Add(file);
			return this;
		}
Пример #3
0
        private IRestRequest AddFile(FileParameter file)
        {
            Files.Add(file);

            return(this);
        }
Пример #4
0
 /// <summary>
 ///     Adds the bytes to the Files collection with the specified file name
 /// </summary>
 /// <param name="name">The parameter name to use in the request</param>
 /// <param name="bytes">The file data</param>
 /// <param name="fileName">The file name to use for the uploaded file</param>
 /// <param name="contentType">The MIME type of the file to upload</param>
 /// <returns>This request</returns>
 public IRestRequest AddFile(string name, byte[] bytes, string fileName, string contentType = null)
 {
     return(AddFile(FileParameter.Create(name, bytes, fileName, contentType)));
 }
Пример #5
0
 /// <summary>
 /// Adds the bytes to the Files collection with the specified file name
 /// </summary>
 /// <param name="name">The parameter name to use in the request</param>
 /// <param name="bytes">The file data</param>
 /// <param name="fileName">The file name to use for the uploaded file</param>
 /// <returns>This request</returns>
 public IRestRequest AddFile(string name, byte[] bytes, string fileName)
 {
     return(AddFile(FileParameter.Create(name, bytes, fileName)));
 }
Пример #6
0
 private IRestRequest AddFile(FileParameter file)
 {
     return(this.With(x => x.Files.Add(file)));
 }
Пример #7
0
        private IRestRequest AddFile(FileParameter file)
        {
            this.Files.Add(file);

            return this;
        }