[MonoTouch] Odd sporatic error on WAV uploads via PUT HTTP request.

jlindborg jlindborg2000 at gmail.com
Sat Dec 17 22:23:06 EST 2011


Hey folks – been banging heads with this for several hours today – just
adding a simple WAV file upload/download facility into my app to a REST
based server – all the downloads work dandy regardless of size, however
uploads will occasionally throw an error on me – if you retry the file a
time or two when you get the failure they do go through but that makes me
sad… I’d rather not have to resort to a retry hack to smother this.  Largely
the same C# code is in use on my WinForms projects and uploads of very large
wav files (long winded voice mail greetings for instance) go through ok to
the same servers.

So… I’m not sure if this is me being a bonehead about something (always a
possibility) or if I’m not taking some iOS limitation into account or this
is a bug somewhere in Mono… anyway – here’s the upload code (simplified a
bit for brevity) .
==========

private static bool UploadWavFile(string pFullResourcePath, string pLogin, 
			  string pPassword, string pLocalWavFilePath)
    {
	Stream oStream = null;
	HttpWebRequest webReq;
	byte[] buffer;
	BinaryReader binReader = null;
              FileStream oFileStream = null;
    
	try
        {
           oFileStream = File.Open(pLocalWavFilePath, FileMode.Open);
           binReader = new BinaryReader(oFileStream);
           buffer = new byte[Convert.ToInt32(binReader.BaseStream.Length) +
1];
           binReader.Read(buffer, 0, buffer.Length);
        }
        catch (Exception ex)
        {
                Console.WriteLine(ex.ToString());
                return false;
        }
	
    webReq = (HttpWebRequest)WebRequest.Create(pFullResourcePath);
    webReq.Method = "PUT";
    webReq.ContentLength = buffer.Length;
    webReq.ContentType = "audio/wav";
    webReq.Credentials = new NetworkCredential(pLogin, pPassword);
    webReq.KeepAlive = false;
    webReq.ReadWriteTimeout= 50000;
    oStream = webReq.GetRequestStream();
	
	Try
		{
                            //LINE THAT THROWS ERROR FROM TIME TO TIME			
                            oStream.Write(buffer,0, buffer.Length);
		}
		catch (Exception ex)
		{
		  Console.WriteLine (ex.ToString());
		  return false;
		}
...

And here’s the error it’s throwing at the noted line:

System.IO.IOException: IO exception during Write. --->
System.NullReferenceException: Object reference not set to an instance of an
object\n  at Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite
(Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00031] in
/Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:775
\n  --- End of inner exception stack trace ---\n  at
Mono.Security.Protocol.Tls.SslStreamBase.InternalBeginWrite
(Mono.Security.Protocol.Tls.InternalAsyncResult asyncResult) [0x00089] in
/Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:788
\n  at Mono.Security.Protocol.Tls.SslStreamBase.BeginWrite (System.Byte[]
buffer, Int32 offset, Int32 count, System.AsyncCallback callback,
System.Object state) [0x000a3] in
/Developer/MonoTouch/Source/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslStreamBase.cs:857
\n  at System.Net.WebConnection.BeginWrite (System.Net.HttpWebRequest
request, System.Byte[] buffer, Int32 offset, Int32 size,
System.AsyncCallback cb, System.Object state) [0x00055] in
/Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnection.cs:927


--
View this message in context: http://monotouch.2284126.n4.nabble.com/Odd-sporatic-error-on-WAV-uploads-via-PUT-HTTP-request-tp4210028p4210028.html
Sent from the MonoTouch mailing list archive at Nabble.com.


More information about the MonoTouch mailing list