WP8 + Upload File to Skydrive

2019-07-16 08:18发布

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.

1条回答
一夜七次
2楼-- · 2019-07-16 08:23

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).

查看更多
登录 后发表回答