2

I'm trying to upload a simple .cer file to SkyDrive. Regardless of the LiveConnectClient-Method I use, nothing happens. There is no compile, runtime or other Exception and my app never receives a LiveOperationResult. I'm using the emulator, and I'm able to log in to MS Live (so my internet connection is fine). Here is a excerpt of the code used:

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
  using(var fileStream = store.OpenFile(certPath, FileMode.Open, FileAccess.Read, FileShare.Read))
  {
    try
    {
      client = new LiveConnectClient(session);
      //LiveOperationResult operationResult = await client.UploadAsync("me/skydrive", certPath, fileStream, OverwriteOption.Overwrite, new System.Threading.CancellationToken(false), null);
      LiveOperationResult res= await client.BackgroundUploadAsync("me/skydrive",
                                                                  new Uri("/shared/transfers/cert.cer", UriKind.Relative),
                                                                  OverwriteOption.Overwrite);
      linkTextBlock.Text = "Done";

As mentioned before, the TextBlock never Displays "Done". It makes no difference if the UploadAsync or BackgroundUploadAsync method is used.

lhan
  • 4,585
  • 11
  • 60
  • 105
Max Meier
  • 21
  • 1
  • 2

1 Answers1

3

BackgroundUploadAsync uses Windows Phone background file transfers which is an intelligent file upload & download scheduling system. Whereas UploadAsync uses immediate HTTP file uploads and downloads.

By using Background file transfers you're agreeing to the following limitations on your upload:

Maximum upload file size

Over cellular connection - 5 MB

Over Wi-Fi connection with battery power - 20 MB

Over Wi-Fi connection with external power - 100 MB

There are also limits on the maximum number of queues uploads & downloads and other limitations. Read the full documentation @ http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202955(v=vs.105).aspx

All of these limitations are probably causing your async await to wait. Even though it's a pain the limits set forth by background file transfers lead to the best user experience (i.e. uplaods when the app is closed), best battery life and best cellular data usage. Ultimately it's up to your app to decide if you want to use straight up WebRequests (uploadAsync) or background file transfers (BackgroundUploadAsync).

Community
  • 1
  • 1
JustinAngel
  • 16,082
  • 3
  • 44
  • 73
  • This API is "intelligent", so it decides what to do with the transfers for you. Let's say you have an instagram-like app with huge pictures, you take a 10MP snapshot, you share it. It will think "I don't want to send it right now, I'm on cellular", even if you set your TransferPreferences to allow battery and cellular. I think they designed it without making the difference between a laptop application and a phone application. Good luck to instagram video. – Léon Pelletier Jul 13 '13 at 18:14