HTTP file request ULTRA SLOW in Unreal. why?

Hi there! I am working on some implementation to download files via HTTP and is working super slow (at least ten times slower than a simple curl request from a terminal

here is the code of my functions

UDownloadFileAsync* UDownloadFileAsync::DownloadFileAsync(FString HttpAddress, FString FileName, FString DestinationFolder, FString AuthToken)
{
    UDownloadFileAsync* Node = NewObject<UDownloadFileAsync>();
    Node->StartDownload(HttpAddress, FileName, DestinationFolder, AuthToken);
    return Node;
}

void UDownloadFileAsync::StartDownload(FString HttpAddress, FString FileName, FString DestinationFolder, FString AuthToken)
{
    if (!HttpAddress.EndsWith(FileName))
    {
        HttpAddress += "/";
        HttpAddress += FileName;
    }
    
    if (FPaths::IsRelative(DestinationFolder))
    {
        DestinationFolder = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir() / DestinationFolder);
    }

    FString FilePath = FPaths::Combine(DestinationFolder, FileName);
    
    if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*DestinationFolder))
    {
        FPlatformFileManager::Get().GetPlatformFile().CreateDirectoryTree(*DestinationFolder);
    }
    
    TSharedRef<IHttpRequest, ESPMode::ThreadSafe> HttpRequest = FHttpModule::Get().CreateRequest();
    HttpRequest->SetURL(HttpAddress);
    HttpRequest->SetVerb("GET");

    if (!AuthToken.IsEmpty())
    {
        HttpRequest->SetHeader("Authorization", "Bearer " + AuthToken);
    }
    
    TWeakObjectPtr<UDownloadFileAsync> WeakThis(this);

    HttpRequest->OnProcessRequestComplete().BindLambda([WeakThis, FilePath](FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
    {
        if (!WeakThis.IsValid()) return;

        bool Success = false;

        if (bWasSuccessful && Response.IsValid())
        {
            const TArray<uint8>& FileData = Response->GetContent();
            if (FileData.Num() > 0)
            {
                Success = FFileHelper::SaveArrayToFile(FileData, *FilePath);
            }
        }

        if (WeakThis.IsValid())
        {
            WeakThis->OnComplete.Broadcast(Success);
        }
    });

    HttpRequest->ProcessRequest();
}

here is the terminal tesst code I do:

curl -o Char01.zip -H "Authorization: Bearer XXXX" "http://mySite.whatever.net:8000/files/Char01.zip"

does anyone has any clue why a 50mb file from a terminal takes like 400ms and in unreal takes like 5000 or 6000? its just a 50mb file and the test I am running is local (server in a gigabit network)

Thanks!

A thread from @Rama of 2016 helped me!!!
He had the same problem 9 years ago
Incredible

anyway…here is the final solution for me:

1 Like