WP8 + Upload File to Skydrive

房东的猫 提交于 2019-12-11 01:28:58

问题


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:


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



来源:https://stackoverflow.com/questions/14482876/wp8-upload-file-to-skydrive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!