IHttpRequest OnRequestProgress only gets called on complete

I’m currently using IHttpRequest to upload files to a web server. The uploads are completing successfully, but I cannot seems to get the progress of the upload. I have tried using OnRequestProgress, but it only gets called once when the upload is complete.

I had expected it to get called periodically, or on every tick, but it does neither. The upload takes a good 30 seconds to complete, so its not that the request is happening too quickly. I also noticed that when the callback does get called at the end it reports 0 bytes sent, 479 received, even after uploading a 4MB file. I am running this on Windows and the debugger reports it is using the CURL implementation of IHttpRequest.

I’m not sure if this is a bug but I suspect it might as the callback is pretty useless otherwise. Has anyone managed to get OnRequestProgress complete functioning as expected?

Looking through the source I discovered the solution to my problem. I was using POST to upload, as my request is a multipart/form-data, however the upload progress callback in FCurlHttpRequest only gets assigned if the request is a PUT.

Essentially OnRequestProgress only gets called when uploading with a PUT request.

Here is the essentials from my upload function (for future reference):

bool FileUploader::UploadFile(FString & filePath, FString & uploadUrl)
{
    TSharedPtr<IHttpRequest> _request;
    _request = FHttpModule::Get().CreateRequest();

    _request->SetURL(uploadUrl);
    _request->SetVerb(TEXT("PUT"));
    _request->SetHeader(TEXT("Content-Type"), "application/octet-stream");

    TArray<uint8> fileData;
    FFileHelper::LoadFileToArray(fileData, *filePath);
    _request->SetContent(fileData);

    _request->OnProcessRequestComplete().BindRaw(this, &FileUploader::OnProcessRequestComplete);
    _request->OnRequestProgress().BindRaw(this, &FileUploader::OnRequestProgress);

    _request->ProcessRequest();
}

And here are the callbacks:

void FileUploader::OnProcessRequestComplete(FHttpRequestPtr request, FHttpResponsePtr response, bool bWasSuccessful) {}

void FileUploader::OnRequestProgress(FHttpRequestPtr request, int32 bytesSent, int32 bytesReceived) {}

Hi, would it be possible for you to post your code regarding this ? I’ve recently added HTTP handling into my codebase but have little to no success getting it working. Even though I followed everything I could find about it, most of it is quite old, 2014 stuff, so the underlying codebase might have changed a lot since.

Sure, I’ve added some example code to my answer.