[Route("uploadToMemory")]// uploads directly to the memory e.g. cloud //The code to accept a file upload directly into memory appart from the validation is very similar, except the fact that once the file is //loaded into a MemoryStream, it’s up to the developer to handle it further. For example, you may wish to save the //Stream to a database or upload it to the cloud. public async Task <List <string> > PostToMemory() { if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); } var provider = new ValidatedMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); var contents = new List <string>(); foreach (HttpContent ctnt in provider.Contents) { var stream = await ctnt.ReadAsStreamAsync(); if (stream.Length != 0) { var sr = new StreamReader(stream); contents.Add(sr.ReadToEnd()); } } return(contents); }
[Route("uploadToMemory")]// uploads directly to the memory e.g. cloud //The code to accept a file upload directly into memory appart from the validation is very similar, except the fact that once the file is //loaded into a MemoryStream, it’s up to the developer to handle it further. For example, you may wish to save the //Stream to a database or upload it to the cloud. public async Task<List<string>> PostToMemory() { if (!Request.Content.IsMimeMultipartContent()) throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted")); var provider = new ValidatedMemoryStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); var contents = new List<string>(); foreach (HttpContent ctnt in provider.Contents) { var stream = await ctnt.ReadAsStreamAsync(); if (stream.Length != 0) { var sr = new StreamReader(stream); contents.Add(sr.ReadToEnd()); } } return contents; }