c# - 如何将多个文件上传到 OneDrive
问题描述
我使用 MS Graph API 将数据迁移到 OneDrive。总数据大小为 100Gb +。
目前我正在做以下事情:
当我在一个文件夹中时,我使用 FileStream 来获取文件:
foreach (var file in System.IO.Directory.GetFiles(startPath))
{
using (FileStream stream = System.IO.File.Open(file, FileMode.Open))
{
string fileName = Path.GetFileName(file);
await WriteFilesToOneDriveAsync(graphClien, stream, user, fileName, folderId);
}
}
当我拥有第一个文件时,我使用以下方法将其上传到 OneDrive:
var driveItemList = await graphServiceClient.Users[user.Id].Drive.Root.Children.Request().GetAsync();
if (!driveItemList.Any(x => x.Name == fileName))
{
UploadSession uploadSession = null;
uploadSession = await graphServiceClient.Users[user.Id].Drive.Root.ItemWithPath(fileName).CreateUploadSession().Request().PostAsync();
var uploadProvider = new ChunkedUploadProvider(uploadSession, graphServiceClient, stream);
var chunks = uploadProvider.GetUploadChunkRequests();
var exceptions = new List<Exception>();
foreach (var (chunk, i) in chunks.WithIndex())
{
var chunkRequestResponse = await uploadProvider.GetChunkRequestResponseAsync(chunk, exceptions);
Console.WriteLine($"Uploading chunk {i} out of {chunks.Count()}");
if (chunkRequestResponse.UploadSucceeded)
{
Console.WriteLine("Upload is complete", chunkRequestResponse.ItemResponse);
}
}
}
else
{
logger.Info($"File Exists {fileName}");
}
这段代码工作得很好。它允许我将文件上传到 OneDrive。
我现在的问题是我有速度问题。将 100Gb 上传到 OneDrive 需要几个小时。根据微软文档:
https://docs.microsoft.com/en-us/sharepointmigration/sharepoint-online-and-onedrive-migration-speed
包装尺寸。为了提高迁移吞吐量,我们建议您每次传输至少打包 250 个文件。对于传输大小,我们建议每个包至少 100 MB 且小于 250 MB。遵守这些准则将加快上传到 Azure 的速度,并利用迁移 API 的扩展功能。
如果我有一个包含 10 个文件(Excel、文本文件...)的文件夹,我如何将这些文件合并到一个包中?
解决方案
推荐阅读
- php - 当左div在运行时为空时,如何将右div向左移动?
- lua - lua:每周在特定日期重置数据
- javascript - 谷歌分析出站链接跟踪在 React 中不起作用
- vba - 删除VBA中空单元格的整行
- java - 带有所选项目图像的 ScrollPane 内的按钮
- python - Py4JJavaError 使用 pyspark ml 库时
- php - 使用随机组排序按组对关联数组进行排序
- php - 我应该使用带有 simplexml_load_file 和 file_get_contents 的代理吗?
- angular - 如何在 PrimeNG 6+ 中使用 JHipster 5+
- arrays - 使用 Dart 解析没有键的 JSON 数组