Beispiel #1
0
		public static NameValueCollection Parse(Stream stream, string contentType, out PostedFile[] files)
		{
			var parser = new MultipartFormDataParser(stream);
			var filesloaded = new List<PostedFile>();
			var form = new NameValueCollection();

			foreach(var f in parser.Files)
			{
				Stream data = f.Data;
				var file = new PostedFile();
				file.Contents = new MemoryStream (f.Data.ReadAllBytes ());
				file.Filename = f.FileName;
				filesloaded.Add (file);
			}

			files = filesloaded.ToArray ();

			var result = new NameValueCollection ();
			foreach (var kvp in parser.Parameters) 
			{
				result.Add (kvp.Key.ToString (), kvp.Value.ToString ());
			}

			return result;
		}
Beispiel #2
0
        public static NameValueCollection Parse(Stream stream, string contentType, out PostedFile[] files)
        {
            var streamContent = new StreamContent(stream);
            var filesloaded = new List<PostedFile>();
            var form = new NameValueCollection();

            streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);

            var provider = awaitReadAsync(streamContent).Result;

            foreach (var content in provider.Contents)
            {
                var fileName = content.Headers.ContentDisposition.FileName;

                if (!string.IsNullOrWhiteSpace(fileName))
                {
                    using (Stream filecontents = awaitReadFileContents(content).Result)
                    {
                        var file = new PostedFile();
                        file.Contents = filecontents.ToMemoryStream();
                        file.Filename = fileName;
                        filesloaded.Add(file);
                    }
                }

                if (content.IsFormData())
                {
                    var formPart = awaitReadFormData(content).Result;
                    form.Add(formPart);
                }

            }

            files = filesloaded.ToArray();


            return form;
        }