void StartUpload() { try { //write to POST request HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.AllowReadStreamBuffering = false; req.Method = "POST"; var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); req.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); var info = new PostRequestInfo() { Files = files, FormData = formData, Request = req, Boundary = boundary, Dispatcher = dispatcher }; if (behavior == FilePostBehavior.OneAtATime) { if (enumerator.MoveNext()) { info.Files = new List<FileInfo> { enumerator.Current }; req.BeginGetRequestStream(GetRequestStream, info); } else { done = true; FinishUpload(info); } } else req.BeginGetRequestStream(GetRequestStream, info); } catch (Exception ex) { OnUploadCompleted(false, ex.Message); } }
//just write the contents of the stream to the output buffer. private void StartRequestForNextChunk() { //next chunk //write to POST request HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "POST"; var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); req.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); var info = new PostRequestInfo() { FormData = formData, Request = req, Boundary = boundary, Dispatcher = dispatcher, Files = new List <FileInfo> { enumerator.Current } }; req.BeginGetRequestStream(WriteRequestStream, info); }
void FinishUpload(PostRequestInfo info) { //request thread this.dispatcher.BeginInvoke(() => { //UI thread if (behavior == FilePostBehavior.OneAtATime && !done) { uploadCount++; OnFileSequenceProgressReport(uploadCount, files.Count()); StartUpload(); } else { //should be totally done. Fire an event to inform the front end that the upload is complete. OnFileSequenceProgressReport(1, 1); OnUploadCompleted(true, null); } }); }
void StartUpload() { try { //write to POST request HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.AllowReadStreamBuffering = false; req.Method = "POST"; var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); req.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); var info = new PostRequestInfo() { Files = files, FormData = formData, Request = req, Boundary = boundary, Dispatcher = dispatcher }; if (behavior == FilePostBehavior.OneAtATime) { if (enumerator.MoveNext()) { info.Files = new List <FileInfo> { enumerator.Current }; req.BeginGetRequestStream(GetRequestStream, info); } else { done = true; FinishUpload(info); } } else { req.BeginGetRequestStream(GetRequestStream, info); } } catch (Exception ex) { OnUploadCompleted(false, ex.Message); } }
//just write the contents of the stream to the output buffer. private void StartRequestForNextChunk() { //next chunk //write to POST request HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "POST"; var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); req.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); var info = new PostRequestInfo() { FormData = formData, Request = req, Boundary = boundary, Dispatcher = dispatcher, Files = new List<FileInfo> { enumerator.Current } }; req.BeginGetRequestStream(WriteRequestStream, info); }