Geeks With Blogs
.Nettuce Code Salad
        void UploadStream(string fileName, Stream stream, string uri, string authorizationHeader)
        {
            var webRequest = WebRequest.Create(uri);
            var boundary = DateTime.Now.Ticks.ToString();
            webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
            webRequest.Method = HttpMethod.Post;
            webRequest.Headers["Authorization"= authorizationHeader;
            var memoryStream = new MemoryStream();
            stream.CopyTo(memoryStream);
            var byteArray = memoryStream.ToArray();
            var postData = new MemoryStream();
            const string newLine = "\r\n";
            var sw = new StreamWriter(postData);
            sw.Write("--" + boundary + newLine);
            sw.Write("Content-Disposition: form-data;name=\"{0}\";filename=\"{1}\"{2}""upload", fileName, newLine + newLine);
            sw.Flush();
            postData.Write(byteArray, 0, byteArray.Length);
            sw.Write(newLine);
            sw.Write("--{0}--{1}", boundary, newLine);
            sw.Flush();
            webRequest.ContentLength = postData.Length;
            using (var requestStream = webRequest.GetRequestStream()) postData.WriteTo(requestStream);
            postData.Close();
        }
Posted on Friday, April 20, 2012 10:09 AM | Back to top


Comments on this post: Multipart form using WebRequest

# re: Multipart form using WebRequest
Requesting Gravatar...
can you send complete working code please???
Left by Faisal on Jul 15, 2016 12:06 PM

Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net