我有活动的API,可以保存图片。
效果很好。
但是,有时会出现错误。
以下是服务器代码:
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;
在 5-10%的API调用中,我收到以下错误:
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()