I created an in-game bug reporter for Industries of Titan. Users can type in a message and it gets sent, along with a screenshot and a zip of their latest save to a server for us to look through.
This is an example of how to set up something similar in C++.
Update: @sswires89 pointed out that this relies on MimeHttpUpload.h
which is currently only available through
UDN. Sorry about the confusion!
BUIUploader.h
#pragma once
#include "Interfaces/IHttpRequest.h"
#include "HttpModule.h"
#include "UI/Util/MimeHttpUpload.h"
#include "BUIUploader.generated.h"
class UBUIUploader
{
GENERATED_BODY()
public:
UBUIUploader( const FObjectInitializer& ObjectInitializer );
FOnMimeUploadHttpRequestComplete RequestCompleteDelegate;
void SendReport();
}
BUIUploader.cpp
#include "BUIUploader.h"
#include "Interfaces/IHttpResponse.h"
#include "UI/Util/MimeHttpUpload.h"
#include "Windows/WindowsPlatformMisc.h"
#include <GenericPlatformFile.h>
UBUIUploader::UBUIUploader( const FObjectInitializer& ObjectInitializer )
: Super( ObjectInitializer )
{
// This will be called when the HTTP post is complete
RequestCompleteDelegate.BindUObject( this, &UBUIUploader::OnRequestComplete );
}
void UBUIUploader::SendReport()
{
TSharedRef<FMimeHttpUpload> MimeUpload = FMimeHttpUpload::Create();
// Basic string values
MimeUpload->AddFormField( "my_key", "Hello World" );
MimeUpload->AddFormField( "another_key", "Great" );
// Take a screenshot
FString RequestedScreenshotPath = FPaths::ScreenShotDir() / "my_screenshot.png";
FScreenshotRequest::RequestScreenshot( RequestedScreenshotPath, true, true );
// Add a screenshot
TArray<uint8> ScreenshotRawData;
FFileHelper::LoadFileToArray( ScreenshotRawData, *FScreenshotRequest::GetFilename() );
MimeUpload->AddAttachment( "screenshot_file", "upload_screenshot.png", "image/png", ScreenshotRawData );
// Add a zip
const FString ZipFilePath = "Fill/This/In/my.zip";
TArray<uint8> SaveZipRawData;
FFileHelper::LoadFileToArray( SaveZipRawData, *ZipFilePath );
MimeUpload->AddAttachment( "zip_file", Filename, "application/zip", SaveZipRawData );
// Send the request
TSharedRef<IHttpRequest> HttpRequest = FHttpModule::Get().CreateRequest();
const FString Url = "http://some.server.com";
MimeUpload->SetupHttpRequest( HttpRequest, Url, RequestCompleteDelegate );
HttpRequest->ProcessRequest();
}
void UBUIUploader::OnRequestComplete( FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful )
{
// Did it work or not?
if ( bWasSuccessful && Response.IsValid() )
{
UE_LOG( LogTemp, Warning, TEXT( "%s" ), *Response->GetContentAsString() );
if ( EHttpResponseCodes::IsOk( Response->GetResponseCode() ) )
{
// Yay we were successful!
}
}
}