How to forward a 'saved' request stream to another Action within the same controller?
Posted
by
Moe Howard
on Stack Overflow
See other posts from Stack Overflow
or by Moe Howard
Published on 2011-11-27T07:21:20Z
Indexed on
2011/11/27
9:51 UTC
Read the original article
Hit count: 483
asp.net-mvc
We have a need to chunk-up large http requests sent by our mobile devices. These smaller chunk streams are merged to a file on the server. Once all chunks are received we need a way to submit the saved merged request to an another method(Action) within the same controller that will process this large http request. How can this be done? The code we tried below results in the service hanging. Is there a way to do this without a round-trip?
//Open merged chunked file
FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
//Read steam support variables
int bytesRead = 0;
byte[] buffer = new byte[1024];
//Build New Web Request. The target Action is called "Upload", this method we are in is called "UploadChunk"
HttpWebRequest webRequest;
webRequest = (HttpWebRequest)WebRequest.Create(Request.Url.ToString().Replace("Chunk", string.Empty));
webRequest.Method = "POST";
webRequest.ContentType = "text/xml";
webRequest.KeepAlive = true;
webRequest.Timeout = 600000;
webRequest.ReadWriteTimeout = 600000;
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
Stream webStream = webRequest.GetRequestStream(); //Hangs here, no errors, just hangs
I have looked into using RedirectToAction and RedirecctToRoute but these methods don't fit well with what we are looking to do as we cannot edit the Request.InputStream (as it is read-only) to carry out large request stream.
Thanks, Moe
© Stack Overflow or respective owner