繁体   English   中英

错误在WP8中使用BackgroundUploadAsync上传文件时?

[英]Error When uploading file with BackgroundUploadAsync in WP8?

我想将录制的文件上传到skydrive,并且正在使用这些代码

用于记录;

void StopRecording()
{
    // Get the last partial buffer
    int sampleSize = microphone.GetSampleSizeInBytes(microphone.BufferDuration);
    byte[] extraBuffer = new byte[sampleSize];
    int extraBytes = microphone.GetData(extraBuffer);

    // Stop recording
    microphone.Stop();

    // Create MemoInfo object and add at top of collection
    int totalSize = memoBufferCollection.Count * sampleSize + extraBytes;
    TimeSpan duration = microphone.GetSampleDuration(totalSize);
    MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration);
    memoFiles.Insert(0, memoInfo);

    // Save data in isolated storage
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = storage.CreateFile("/shared/transfers/" + memoInfo.FileName))
        {
            // Write buffers from collection
            foreach (byte[] buffer in memoBufferCollection)
                stream.Write(buffer, 0, buffer.Length);

            // Write partial buffer
            stream.Write(extraBuffer, 0, extraBytes);
        }
    }
}

用于上传文件;

async void OnSaveButtonClick(object sender, RoutedEventArgs args)
{
    Button btn = sender as Button;
    MemoInfo clickedMemoInfo = btn.Tag as MemoInfo;
    memosListBox.SelectedItem = clickedMemoInfo;
    if (this.client == null)
    {
        gridSingin.Visibility = Visibility.Visible;
        memosListBox.Visibility = Visibility.Collapsed;
    }
    else
    {
        using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (var fileStream = store.OpenFile(clickedMemoInfo.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive",
                                                                            new Uri("/shared/transfers/" + clickedMemoInfo.FileName, UriKind.Relative),
                                                                            OverwriteOption.Overwrite
                                                                            );
                InfoText.Text = "File " + clickedMemoInfo.FileName + " uploaded";
            }
        }
    }
}

但是我在这里开始错误

LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive", new Uri("/shared/transfers/" + clickedMemoInfo.FileName, UriKind.Relative), OverwriteOption.Overwrite);

我收到此错误;

System.Windows.ni.dll中发生了类型为'System.Reflection.TargetInvocationException'的未处理异常

请问你能帮帮我吗?

尝试上传时无法打开文件。 尝试这样做。

using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
    if (store.FileExists(fileName))
    {
        client.BackgroundUploadAsync("me/skydrive", new Uri(fileName, UriKind.Relative),
                                        OverwriteOption.Overwrite);

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM