9
I find that my HTTPWebRequest Upload is failing at the very end of the upload ... as shown in this video @Screenr
My Code is like below
using (var reqStream = req.GetRequestStream())
{
BinaryWriter reqWriter = new BinaryWriter(reqStream);
byte[] buffer = new byte[25600]; // 20KB Buffer
int read = 0, bytesRead = 0;
while ((read = memStream.Read(buffer, 0, buffer.Length)) > 0) {
reqWriter.Write(buffer); // at the very last loop, this line causes the error
bytesRead += read;
Debug.WriteLine("Percent Done: " + ((double)bytesRead / memStream.Length * 100) + "% " + DateTime.Now);
}
I don't know if you need more code, I just don't want to spam code here. the exception below
System.Net.WebException was caught
Message=The request was aborted: The request was canceled.
Source=System
StackTrace:
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.ConnectStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at QuickImageUpload.ViewModels.ShellViewModel.UploadImage(String filename, String contentType, Byte[] image) in D:\Projects\QuickImageUpload\QuickImageUpload\ViewModels\ShellViewModel.cs:line 190
InnerException: System.IO.IOException
Message=Cannot close stream until all bytes are written.
Source=System
StackTrace:
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
InnerException:
Notice the inner exception "Cannot close stream until all bytes are written.". But I havent close any streams in this loop have I?