Search code examples
c#xamarin.ioswebclienthttp-upload

Best way to upload files from iOS app to Windows Server?


My iOS application allows a user to store files such as PDF's, Images, etc. We need to synchronize the app files to the cloud as we also offer the user a web portal to view the same data. I use WCF (Mtom encoding/streaming) in my Windows Forms app but this is not working in Xamarion.iOS (MonoTouch). There seems to be a problem with Mtom message encoding so I'm looking at an alternate and/or better way of getting files uploaded reliably such as streaming, showing progress, and using async await in C# 5 if possible.

What method do you recommend and if you have any sample code or links this would be great. Also, what is required in IIS 7.5 as I run Windows Server 2008 R2. Lastly, any firewall issues as I run a Watchguard appliance so if I need to open anything to allow this to work please advise. I assume though this would occur over HTTP or HTTPS.

I've done some research on web client, webDAV, etc, but not sure what is really the best approach for this scenario.

Thank you.


Solution

  • HttpClient (async) or WebClient will handle uploads just fine. You can create an ASP.NET upload handler or MVC action to read a HTTP posted file.

    Some helpful links:

    C# HttpClient 4.5 multipart/form-data upload

    Getting the upload progress during file upload using Webclient.Uploadfile

    http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx

    Edit: See Larry OBrien's answer explaining the iOS 7 native MonoTouch.Foundation.NSUrlSession which allows background transfers.