[MonoTouch] Odd sporatic error on WAV uploads via PUT HTTP request.
Rolf Bjarne Kvinge
rolf at xamarin.com
Mon Dec 19 19:23:49 EST 2011
Hi,
I don't know exactly what's going on, but I have a few questions that might
help you:
* It seems you're using https, do you have the same problem with just http?
* Does it fail instantly when it fails, or does it start uploading and then
fail after some random amount of time?
* (If it doesn't fail instantly) does a slow network make it fail
faster/more often?
* You say you're uploading "very large wav files", but exactly how large is
"very large"?
I don't think it's an iOS restriction you're running into if it works
sometimes. To me it sounds either like a network hiccup, or an obscure bug
inside MonoTouch (and the questions above will help point the location, but
in any case a reproducible test case would likely be required to track down
a MonoTouch bug).
Rolf
On Sun, Dec 18, 2011 at 4:23 AM, jlindborg <jlindborg2000 at gmail.com> wrote:
> 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.
> _______________________________________________
> MonoTouch mailing list
> MonoTouch at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20111220/04652a96/attachment.html
More information about the MonoTouch
mailing list