我想将文件上传到UWP
的LocalFolder。它适用于图像。但是对于一些大的mp4
文件,它已经存在异常并显示错误
“System.Runtime.InteropServices.COMException:错误HRESULT E_FAIL已从调用COM组件返回。”
private async void BtnTestUpload_ClickAsync(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
picker.FileTypeFilter.Add(".mp4");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
try
{
await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.FailIfExists);
var dialog = new MessageDialog("Upload Successfull");
await dialog.ShowAsync();
}
catch (Exception ex)
{
var dialog = new MessageDialog("fail" + ex.ToString());
await dialog.ShowAsync();
}
}
}