Overview
Runtime Files Downloader is a plugin for downloading files over HTTP / HTTPS at runtime.
How to use
If you need to save a file to storage, then you need to call DownloadFileToStorage function.
- Blueprint
- C++
UFileToStorageDownloader::DownloadFileToStorage(TEXT("https://example.com/File.zip"), TEXT("C:/Folder/File.zip"), 15.0f, TEXT(""), false,
FOnDownloadProgressNative::CreateLambda([](int64 BytesReceived, int64 ContentSize, float ProgressRatio)
{
UE_LOG(LogTemp, Log, TEXT("Download progress: %f"), ProgressRatio);
}), FOnFileToStorageDownloadCompleteNative::CreateLambda([](EDownloadToStorageResult Result, const FString& SavedPath, UFileToStorageDownloader* Downloader)
{
UE_LOG(LogTemp, Log, TEXT("Download complete, result: %s, saved path: %s"), *UEnum::GetValueAsString(Result), *SavedPath);
}));
If you do not need to save the file, but just get access to the downloaded content, then you need to call DownloadFileToMemory function.
- Blueprint
- C++
UFileToMemoryDownloader::DownloadFileToMemory(TEXT("https://example.com/File.zip"), 15.0f, TEXT(""), false,
FOnDownloadProgressNative::CreateLambda([](int64 BytesReceived, int64 ContentSize, float ProgressRatio)
{
UE_LOG(LogTemp, Log, TEXT("Download progress: %f"), ProgressRatio);
}), FOnFileToMemoryDownloadCompleteNative::CreateLambda([](const TArray64<uint8>& DownloadedContent, EDownloadToMemoryResult Result, UFileToMemoryDownloader* Downloader)
{
UE_LOG(LogTemp, Log, TEXT("Download complete, result: %s, DownloadedContent size: %d"), *UEnum::GetValueAsString(Result), DownloadedContent.Num());
}));
Optionally, you can specify the type of file to download by entering a MIME type in the Content Type
field.
A list of the most common MIME types is listed here.
After the download has started, you can cancel it using the CancelDownload function.
- Blueprint
- C++
// Assuming Downloader is a UE reference to a UFileToStorageDownloader or UFileToMemoryDownloader object
Downloader->CancelDownload();
Please note that starting from UE 5.4, the Timeout parameter behaves in a way that cancels the request during the download itself if the overall time taken for downloading exceeds the Timeout, which is somewhat a bug in UE. Please either specify a large value (such as 3600 seconds, which is 1 hour) or specify it as zero to disable the Timeout completely.
Live example
There is an example of a simple Android game that demonstrates the plugin's ability.