Skip to content

Transfers

IHttpTransferManager manages background upload and download operations. Each transfer is defined by an HttpTransferRequest.

PropertyTypeDescription
IdentifierstringUnique ID for this transfer
UristringThe remote URL
TypeTransferTypeDownload, UploadRaw, or UploadMultipart
LocalFilePathstringPath to the local file
UseMeteredConnectionboolAllow transfer on metered networks (default: true)
HttpContentTransferHttpContent?Additional content for uploads
HeadersIDictionary<string, string>?Custom HTTP headers
IHttpTransferManager manager; // injected
var request = new HttpTransferRequest(
Identifier: "download-1",
Uri: "https://example.com/largefile.zip",
Type: TransferType.Download,
LocalFilePath: Path.Combine(FileSystem.AppDataDirectory, "largefile.zip")
);
var transfer = await manager.Queue(request);
var request = new HttpTransferRequest(
Identifier: "upload-1",
Uri: "https://example.com/upload",
Type: TransferType.UploadRaw,
LocalFilePath: "/path/to/file.dat"
);
await manager.Queue(request);

Send a file with additional form data and headers.

var request = new HttpTransferRequest(
Identifier: "upload-2",
Uri: "https://example.com/upload",
Type: TransferType.UploadMultipart,
LocalFilePath: "/path/to/photo.jpg",
Headers: new Dictionary<string, string>
{
{ "Authorization", "Bearer your-token" }
},
HttpContent: TransferHttpContent.FromFormData(
("description", "My photo"),
("category", "images")
)
);
await manager.Queue(request);
// JSON content
var content = TransferHttpContent.FromJson(new { name = "test", value = 42 });
// Form data
var content = TransferHttpContent.FromFormData(
("field1", "value1"),
("field2", "value2")
);
// Form data from dictionary
var dict = new Dictionary<string, string> { { "key", "value" } };
var content = TransferHttpContent.FromFormData(dict);
var transfers = await manager.GetTransfers();
foreach (var transfer in transfers)
{
Console.WriteLine($"{transfer.Identifier}: {transfer.Status}");
}
// Cancel a specific transfer
await manager.Cancel("upload-1");
// Cancel all transfers
await manager.CancelAll();