Client Disconnected Error on calling Web API

5

I have and active API with actions that can save images.

It works well.

However, sometimes there are errors.

Below is the server code:

var appData = HostingEnvironment.MapPath("~/App_Data");
string dirname = Guid.NewGuid().ToString();
var folder = Path.Combine(appData, dirname);
Directory.CreateDirectory(folder);
var provider = new MultipartFormDataStreamProvider(folder);
var result = await Request.Content.ReadAsMultipartAsync(provider);
var type = result.FileData
                    .First()
                    .Headers
                    .ToList()
                    .First()
                    .Value
                    .First()
                    .Split(';')[2]
                    .Split('=')[1]
                    .Replace("\"", "")
                    .Split('.')[1];
if (result.FileData.Count < 1)
{
 // ...
}            
string name = result.FileData.First().LocalFileName;

On 5-10% of the API calls I'm getting the following error:

Error reading MIME multipart body part. | 
System.Web.HttpException (0x800703E3): The client disconnected. 
    at System.Web.Hosting.IIS7WorkerRequest.EndRead(IAsyncResult asyncResult) at
    System.Web.HttpBufferlessInputStream.EndRead(IAsyncResult asyncResult) at
    System.IO.Stream.b__e(Stream stream, IAsyncResult asyncResult) at
    System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at
    System.Web.Http.WebHost.SeekableBufferedRequestStream.d__0.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at 
    System.Net.Http.HttpContentMultipartExtensions.d__8.MoveNext()
c#
.net
api
mime
asked on Stack Overflow Oct 27, 2014 by ItayM • edited Mar 3, 2015 by Ian Chu Te

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0