Tổng quan

Runtime Files Downloader là một plugin để tải tệp qua HTTP / HTTPS trong thời gian chạy.
Cách sử dụng
Nếu bạn cần lưu một tệp vào bộ nhớ, thì bạn cần gọi hàm DownloadFileToStorage.
- 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);
}));
Nếu bạn không cần lưu tệp, mà chỉ cần truy cập vào nội dung đã tải xuống, thì bạn cần gọi hàm DownloadFileToMemory.
- 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());
}));
Tùy chọn, bạn có thể chỉ định loại tệp để tải xuống bằng cách nhập loại MIME vào trường Content Type.
Danh sách các loại MIME phổ biến nhất được liệt kê tại đây.
Sau khi quá trình tải xuống bắt đầu, bạn có thể hủy nó bằng cách sử dụng hàm CancelDownload.
- Blueprint
- C++

// Assuming Downloader is a UE reference to a UFileToStorageDownloader or UFileToMemoryDownloader object
Downloader->CancelDownload();
Xin lưu ý rằng bắt đầu từ UE 5.4, tham số Timeout hoạt động theo cách hủy yêu cầu trong quá trình tải xuống nếu tổng thời gian tải xuống vượt quá Timeout, đây là một lỗi của UE. Vui lòng chỉ định một giá trị lớn (chẳng hạn như 3600 giây, tức 1 giờ) hoặc chỉ định giá trị bằng 0 để tắt hoàn toàn Timeout.
Tài nguyên bổ sung
- Mua trên Fab
- Hỗ trợ Plugin & Phát triển tùy chỉnh: [email protected] (giải pháp tùy chỉnh cho các nhóm và tổ chức)