我有一个 BackgroundUploader 实例,我通过 put 方法将一些文件上传到 webdav 服务器。这没有任何问题。现在在 BackgroundUploader 命名空间中,有一个 BackgroundTransferContentPart 方法,用于上传多个文件。我不知道如何以正确的方式进行操作,因为我必须将文件名添加到 URI,以便将文件放在服务器上。在 BackgroundTransferContentPart 上,URI 只指定一次,没有文件名,那么我该如何上传多个文件呢?
编辑:这是我的代码
private async void UploadAllFiles()
{
// URI
Uri uri = new Uri("https://example.com/upload/");
// FileOpenPicker
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
// Files
List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
for (int i = 0; i < files.Count; i++)
{
BackgroundTransferContentPart part = new BackgroundTransferContentPart("File" + i, files[i].Name);
part.SetFile(files[i]);
parts.Add(part);
}
// Credentials
string userName = "username";
string passWord = "password";
var creds = new PasswordCredential("login", userName, passWord);
// BG-Uploader
BackgroundUploader uploader = new BackgroundUploader();
uploader.SetRequestHeader("RequestId", file.DisplayName);
uploader.Method = "PUT";
uploader.ServerCredential = creds;
// Create operation
UploadOperation upload = await uploader.CreateUploadAsync(uri, parts);
// Upload
await upload.StartAsync().AsTask(cts.Token, progressCallback);
}