我正在以这种方式在我的UWP应用程序中下载一些.zip文件。
var rootFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("attachment", CreationCollisionOption.OpenIfExists );
FileInfo fInfo;
this.infoFiles.TryTake(out fInfo);
StorageFile coverpic = await rootFolder.CreateFileAsync(fInfo.FileName, CreationCollisionOption.ReplaceExisting);
try
{
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
Uri URI = new Uri(fInfo.Url);
byte[] buffer = await client.GetByteArrayAsync(URI); // Download file
using (Stream stream = await coverpic.OpenStreamForWriteAsync())
stream.Write(buffer, 0, buffer.Length); // Save
StorageFile zipFile = await MyFileHelper.GetFileAsync(rootFolder, fInfo.FileName);
if (fInfo.FileName.ToLower().Contains(".zip"))
{
await UnZipFileAsync(zipFile, rootFolder).ConfigureAwait(false);
if (Instance.DownloadedNotification != null)
{
Instance.DownloadedNotification(fInfo.FileName);
}
if (await rootFolder.TryGetItemAsync("5301.zip") != null)
{
Debug.WriteLine("Soon after Download and Unzip finished 5301.zip exists");
}
else
{
Debug.WriteLine("Soon after Download and Unzip finished 5301.zip doesn't exists");
}
}
else
{
if (Instance.DownloadedNotification != null)
{
Instance.DownloadedNotification(fInfo.FileName);
}
if (await rootFolder.TryGetItemAsync("5301.zip") != null)
{
Debug.WriteLine("Soon after Download and Unzip finished and file name doesn't contain "zipFile" 5301.zip exists");
}
else
{
Debug.WriteLine("Soon after Download and Unzip finished and file name doesn't contain "zipFile" 5301.zip doesn't exists");
}
}
// return coverpic;
}
catch (Exception e)
{
Debug.WriteLine("Exception Occured--" + e.Message);
}
我正在异步下载 30 多个文件。我下载了1个文件并保存。然后解压缩它(实际上我正在阅读.zip文件的内容而不解压缩它。然后将包含的文件复制到根文件夹(。成功复制后,我正在下载第二个.zip文件。
我的问题是,在这个周期进行时,根文件夹中缺少一些已经下载的文件(.zip文件和解压缩文件都从根文件夹中丢失(。 例如,假设 5301.zip 文件下载并解压缩为第一个文件。如果程序正在下载第 10 个文件(5310.zip(,则此 5301.zip 文件和解压缩的文件都将丢失。 我的文件正在下载到
C:\Users\myuser\AppData\Local\Packages\de187d8d-my-app-id-2b3b8a255c7b_tqgs61w0frgtm\LocalState\attachment
为什么会这样?请指导我解决此问题。 谢谢!
如果您使用的是插件Cordova-file-transfer,为Windows 22H2编译,请验证您的Windows是否具有加密驱动器,这是这里的问题,导致下载,然后消失,因为加密。